<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">-- Copyright 2016 TensorFlow authors.</span><span>
</span><span id="line-2"></span><span class="hs-comment">--</span><span>
</span><span id="line-3"></span><span class="hs-comment">-- Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- you may not use this file except in compliance with the License.</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- You may obtain a copy of the License at</span><span>
</span><span id="line-6"></span><span class="hs-comment">--</span><span>
</span><span id="line-7"></span><span class="hs-comment">--     http://www.apache.org/licenses/LICENSE-2.0</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Unless required by applicable law or agreed to in writing, software</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- See the License for the specific language governing permissions and</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- limitations under the License.</span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-pragma">{-# LANGUAGE ConstraintKinds #-}</span><span>
</span><span id="line-16"></span><span class="hs-pragma">{-# LANGUAGE DataKinds #-}</span><span>
</span><span id="line-17"></span><span class="hs-pragma">{-# LANGUAGE FlexibleContexts #-}</span><span>
</span><span id="line-18"></span><span class="hs-pragma">{-# LANGUAGE OverloadedStrings #-}</span><span>
</span><span id="line-19"></span><span class="hs-pragma">{-# LANGUAGE RankNTypes #-}</span><span>
</span><span id="line-20"></span><span class="hs-pragma">{-# LANGUAGE ScopedTypeVariables #-}</span><span>
</span><span id="line-21"></span><span class="hs-pragma">{-# LANGUAGE TypeFamilies #-}</span><span>
</span><span id="line-22"></span><span class="hs-pragma">{-# LANGUAGE ViewPatterns #-}</span><span>
</span><span id="line-23"></span><span class="hs-pragma">{-# LANGUAGE TypeApplications #-}</span><span>
</span><span id="line-24"></span><span>
</span><span id="line-25"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">TensorFlow.Gradient</span><span>
</span><span id="line-26"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientCompatible"><span class="hs-identifier">GradientCompatible</span></a></span><span>
</span><span id="line-27"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#gradients"><span class="hs-identifier">gradients</span></a></span><span>
</span><span id="line-28"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-29"></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Monad</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">forM</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">zipWithM</span></span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Monad.State.Strict</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">State</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">evalState</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">gets</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">modify</span></span><span class="hs-special">)</span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.ByteString</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">ByteString</span></span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Complex</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Complex</span></span><span class="hs-special">)</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.ProtoLens.Default</span></span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">def</span></span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Int</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Int32</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">Int64</span></span><span class="hs-special">)</span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Foldable</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">foldlM</span></span><span class="hs-special">)</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.List</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">foldl'</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">sortBy</span></span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Map.Strict</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Map</span></span><span class="hs-special">)</span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.IntSet</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IntSet</span></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">fromMaybe</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">maybeToList</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">mapMaybe</span></span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Ord</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">comparing</span></span><span class="hs-special">)</span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.ProtoLens.TextFormat</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">showMessage</span></span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Set</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Set</span></span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Text</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Text</span></span><span class="hs-special">)</span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Tuple</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">swap</span></span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Lens.Family2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Lens'</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">view</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-operator">(&amp;)</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-operator">(^.)</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-operator">(.~)</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-operator">(%~)</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">under</span></span><span class="hs-special">)</span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Lens.Family2.State.Strict</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">uses</span></span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Lens.Family2.Stock</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">at</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">intAt</span></span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Lens.Family2.Unchecked</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">lens</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">adapter</span></span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Prelude</span></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">sum</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">tanh</span></span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Text.Printf</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">printf</span></span><span class="hs-special">)</span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Graph.Inductive.Basic</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FGL</span></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Graph.Inductive.Graph</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FGL</span></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Graph.Inductive.PatriciaTree</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FGL</span></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Graph.Inductive.Query.DFS</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FGL</span></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.IntMap.Strict</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IntMap</span></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Map.Strict</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Map</span></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Set</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Set</span></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Text</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Text</span></span><span>
</span><span id="line-60"></span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">TensorFlow.GenOps.Core</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">CoreOps</span></span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">TensorFlow.Build</span></span><span>
</span><span id="line-63"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="hs-identifier">MonadBuild</span></span><span>
</span><span id="line-64"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">Build</span></span><span>
</span><span id="line-65"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">build</span></span><span>
</span><span id="line-66"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">renderedNodeDefs</span></span><span>
</span><span id="line-67"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">opDef</span></span><span>
</span><span id="line-68"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">opAttr</span></span><span>
</span><span id="line-69"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">opInputs</span></span><span>
</span><span id="line-70"></span><span>    </span><span class="hs-special">)</span><span>
</span><span id="line-71"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">TensorFlow.BuildOp</span></span><span>
</span><span id="line-72"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="TensorFlow.Ops.html"><span class="hs-identifier">TensorFlow.Ops</span></a></span><span>
</span><span id="line-73"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="hs-identifier">addN</span></span><span>
</span><span id="line-74"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">broadcastGradientArgs</span></span><span>
</span><span id="line-75"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Ops.html#expandDims"><span class="hs-identifier">expandDims</span></a></span><span>
</span><span id="line-76"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">fill</span></span><span>
</span><span id="line-77"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">matMul</span></span><span>
</span><span id="line-78"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">matMul'</span></span><span>
</span><span id="line-79"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Ops.html#reducedShape"><span class="hs-identifier">reducedShape</span></a></span><span>
</span><span id="line-80"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">reluGrad</span></span><span>
</span><span id="line-81"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">tanh</span></span><span>
</span><span id="line-82"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">tanhGrad</span></span><span>
</span><span id="line-83"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">reshape</span></span><span>
</span><span id="line-84"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Ops.html#scalar"><span class="hs-identifier">scalar</span></a></span><span>
</span><span id="line-85"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier">shape</span></a></span><span>
</span><span id="line-86"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">softmaxCrossEntropyWithLogits</span></span><span>
</span><span id="line-87"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">sum</span></span><span>
</span><span id="line-88"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">sigmoid</span></span><span>
</span><span id="line-89"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">sigmoidGrad</span></span><span>
</span><span id="line-90"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Ops.html#scalarize"><span class="hs-identifier">scalarize</span></a></span><span>
</span><span id="line-91"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier">vector</span></a></span><span>
</span><span id="line-92"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">zerosLike</span></span><span>
</span><span id="line-93"></span><span>    </span><span class="hs-special">)</span><span>
</span><span id="line-94"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">TensorFlow.Output</span></span><span>
</span><span id="line-95"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="hs-identifier">NodeName</span></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-96"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">Output</span></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-97"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">OutputIx</span></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-98"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">outputIndex</span></span><span>
</span><span id="line-99"></span><span>    </span><span class="hs-special">)</span><span>
</span><span id="line-100"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">TensorFlow.Tensor</span></span><span>
</span><span id="line-101"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="hs-identifier">Tensor</span></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-102"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">Value</span></span><span>
</span><span id="line-103"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">render</span></span><span>
</span><span id="line-104"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">expr</span></span><span>
</span><span id="line-105"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">Rendered</span></span><span>
</span><span id="line-106"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">tensorNodeName</span></span><span>
</span><span id="line-107"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">renderedOutput</span></span><span>
</span><span id="line-108"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">renderValue</span></span><span>
</span><span id="line-109"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">ToTensor</span></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-110"></span><span>    </span><span class="hs-special">)</span><span>
</span><span id="line-111"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">TensorFlow.Types</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Attribute</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">OneOf</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">TensorType</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">attrLens</span></span><span class="hs-special">)</span><span>
</span><span id="line-112"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Proto.Tensorflow.Core.Framework.NodeDef</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">NodeDef</span></span><span class="hs-special">)</span><span>
</span><span id="line-113"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Proto.Tensorflow.Core.Framework.NodeDef_Fields</span></span><span>
</span><span id="line-114"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="hs-identifier">attr</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">input</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">op</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">name</span></span><span class="hs-special">)</span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span class="hs-keyword">type</span><span> </span><span id="GradientCompatible"><span class="annot"><a href="TensorFlow.Gradient.html#GradientCompatible"><span class="hs-identifier hs-var">GradientCompatible</span></a></span></span><span> </span><span id="local-6989586621679156923"><span class="annot"><a href="#local-6989586621679156923"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-117"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): MaxPoolGrad doesn't support Double for some reason.</span><span>
</span><span id="line-118"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Num</span></span><span> </span><span class="annot"><a href="#local-6989586621679156923"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OneOf</span></span><span> </span><span class="hs-special">'</span><span class="hs-special">[</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Complex</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Complex</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Double</span></span><span> </span><span class="hs-special">]</span><span> </span><span class="annot"><a href="#local-6989586621679156923"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-119"></span><span>
</span><span id="line-120"></span><span class="hs-comment">-- TODO(fmayle): Support control flow.</span><span>
</span><span id="line-121"></span><span class="hs-comment">-- TODO(fmayle): Support gate_gradients-like option to avoid race conditions.</span><span>
</span><span id="line-122"></span><span class="hs-comment">-- TODO(fmayle): Do we need to consider control inputs? See _PendingCount in</span><span>
</span><span id="line-123"></span><span class="hs-comment">-- tensorflow/python/ops/gradients.py.</span><span>
</span><span id="line-124"></span><span class="hs-comment">-- TODO(fmayle): Maybe store the gradient functions and numOutputs on the OpDef.</span><span>
</span><span id="line-125"></span><span>
</span><span id="line-126"></span><span>
</span><span id="line-127"></span><span class="hs-comment">-- | Gradient of @y@ w.r.t. each element of @xs@.</span><span>
</span><span id="line-128"></span><span class="annot"><a href="TensorFlow.Gradient.html#gradients"><span class="hs-identifier hs-type">gradients</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679156922"><span class="annot"><a href="#local-6989586621679156922"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span id="local-6989586621679156921"><span class="annot"><a href="#local-6989586621679156921"><span class="hs-identifier hs-type">v1</span></a></span></span><span> </span><span id="local-6989586621679156920"><span class="annot"><a href="#local-6989586621679156920"><span class="hs-identifier hs-type">t</span></a></span></span><span> </span><span id="local-6989586621679156919"><span class="annot"><a href="#local-6989586621679156919"><span class="hs-identifier hs-type">m</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="hs-identifier hs-type">MonadBuild</span></span><span> </span><span class="annot"><a href="#local-6989586621679156919"><span class="hs-identifier hs-type">m</span></a></span><span>
</span><span id="line-129"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Rendered</span></span><span> </span><span class="annot"><a href="#local-6989586621679156920"><span class="hs-identifier hs-type">t</span></a></span><span>
</span><span id="line-130"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ToTensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679156920"><span class="hs-identifier hs-type">t</span></a></span><span>
</span><span id="line-131"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientCompatible"><span class="hs-identifier hs-type">GradientCompatible</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679156922"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-132"></span><span>                               </span><span class="hs-special">)</span><span>
</span><span id="line-133"></span><span>          </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679156921"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679156922"><span class="hs-identifier hs-type">a</span></a></span><span>  </span><span class="hs-comment">-- ^ The output of the graph.</span><span>
</span><span id="line-134"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679156920"><span class="hs-identifier hs-type">t</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679156922"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span>        </span><span class="hs-comment">-- ^ Tensors for which gradients are computed.</span><span>
</span><span id="line-135"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679156919"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Value</span></span><span> </span><span class="annot"><a href="#local-6989586621679156922"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-136"></span><span id="gradients"><span class="annot"><span class="annottext">gradients :: Tensor v1 a -&gt; [t a] -&gt; m [Tensor Value a]
</span><a href="TensorFlow.Gradient.html#gradients"><span class="hs-identifier hs-var hs-var">gradients</span></a></span></span><span> </span><span id="local-6989586621679156918"><span class="annot"><span class="annottext">y :: Tensor v1 a
</span><a href="#local-6989586621679156918"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span id="local-6989586621679156917"><span class="annot"><span class="annottext">xs :: [t a]
</span><a href="#local-6989586621679156917"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Build [Tensor Value a] -&gt; m [Tensor Value a]
forall (m :: * -&gt; *) a. MonadBuild m =&gt; Build a -&gt; m a
</span><span class="hs-identifier hs-var">build</span></span><span> </span><span class="annot"><span class="annottext">(Build [Tensor Value a] -&gt; m [Tensor Value a])
-&gt; Build [Tensor Value a] -&gt; m [Tensor Value a]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-137"></span><span>    </span><span class="hs-comment">-- The gradients are computed using &quot;reverse accumulation&quot;, similarly to</span><span>
</span><span id="line-138"></span><span>    </span><span class="hs-comment">-- what is described here:</span><span>
</span><span id="line-139"></span><span>    </span><span class="hs-comment">-- https://en.wikipedia.org/wiki/Automatic_differentiation#The_chain_rule.2C_forward_and_reverse_accumulation</span><span>
</span><span id="line-140"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-141"></span><span>    </span><span class="hs-comment">-- The code is summarised as follows:</span><span>
</span><span id="line-142"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-143"></span><span>    </span><span class="hs-comment">-- 1. Create an fgl graph of the relevant nodes (ops) and edges (tensors).</span><span>
</span><span id="line-144"></span><span>    </span><span class="hs-comment">-- 2. Initialize the gradient of y to 1 (&#8706;y/&#8706;y = 1) and the rest of tensor's</span><span>
</span><span id="line-145"></span><span>    </span><span class="hs-comment">--    gradients to nothing.</span><span>
</span><span id="line-146"></span><span>    </span><span class="hs-comment">-- 3. Process the nodes in reverse topological order (i.e. each node comes</span><span>
</span><span id="line-147"></span><span>    </span><span class="hs-comment">--    after all of its outputs so that the output gradients for a node have</span><span>
</span><span id="line-148"></span><span>    </span><span class="hs-comment">--    been completely calculated before it is processed):</span><span>
</span><span id="line-149"></span><span>    </span><span class="hs-comment">--      a. Record the gradient for each of the node's output tensors (&#8706;y/&#8706;w</span><span>
</span><span id="line-150"></span><span>    </span><span class="hs-comment">--         for each output tensor w).</span><span>
</span><span id="line-151"></span><span>    </span><span class="hs-comment">--      b. Calculate the gradient of y w.r.t. each of the node's input</span><span>
</span><span id="line-152"></span><span>    </span><span class="hs-comment">--         tensors using the gradients of the node's output tensors.</span><span>
</span><span id="line-153"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-154"></span><span>    </span><span class="hs-comment">--         Written differently, for each output tensor w and input tensor v:</span><span>
</span><span id="line-155"></span><span>    </span><span class="hs-comment">--           &#8706;y/&#8706;w = ...            (calculated in previous steps)</span><span>
</span><span id="line-156"></span><span>    </span><span class="hs-comment">--           &#8706;w/&#8706;v = ...            (op specific)</span><span>
</span><span id="line-157"></span><span>    </span><span class="hs-comment">--           &#8706;y/&#8706;v = &#8706;y/&#8706;w * &#8706;w/&#8706;v  (technically, if tensor v is an input</span><span>
</span><span id="line-158"></span><span>    </span><span class="hs-comment">--                                   to multiple nodes, then this is only</span><span>
</span><span id="line-159"></span><span>    </span><span class="hs-comment">--                                   part of &#8706;y/&#8706;v)</span><span>
</span><span id="line-160"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-161"></span><span>    </span><span class="hs-comment">-- 4. Lookup the recorded gradient for each x in xs.</span><span>
</span><span id="line-162"></span><span>
</span><span id="line-163"></span><span>    </span><span id="local-6989586621679156916"><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156916"><span class="hs-identifier hs-var">y'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Tensor v1 a -&gt; BuildT Identity (Tensor Value a)
forall (m :: * -&gt; *) (v :: * -&gt; *) a.
MonadBuild m =&gt;
Tensor v a -&gt; m (Tensor Value a)
</span><span class="hs-identifier hs-var">renderValue</span></span><span> </span><span class="annot"><span class="annottext">Tensor v1 a
</span><a href="#local-6989586621679156918"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-164"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156915"><span class="annot"><span class="annottext">yName :: NodeName
</span><a href="#local-6989586621679156915"><span class="hs-identifier hs-var hs-var">yName</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; NodeName
forall (t :: * -&gt; *) a. Rendered t =&gt; t a -&gt; NodeName
</span><span class="hs-identifier hs-var">tensorNodeName</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156916"><span class="hs-identifier hs-var">y'</span></a></span><span>
</span><span id="line-165"></span><span>    </span><span id="local-6989586621679156914"><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156914"><span class="hs-identifier hs-var">yOne</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; BuildT Identity (Tensor Value a)
forall (m :: * -&gt; *) a.
MonadBuild m =&gt;
Tensor Build a -&gt; m (Tensor Value a)
</span><span class="hs-identifier hs-var">render</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; BuildT Identity (Tensor Value a))
-&gt; Tensor Build a -&gt; BuildT Identity (Tensor Value a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t index_type.
(TensorType t, OneOf '[Int32, Int64] index_type) =&gt;
Tensor v'1 index_type -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">fill</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156916"><span class="hs-identifier hs-var">y'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Tensor Build a
forall a. TensorType a =&gt; a -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#scalar"><span class="hs-identifier hs-var">scalar</span></a></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-166"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): Move this into Build.hs and call it unsafeNodeDefFromName?</span><span>
</span><span id="line-167"></span><span>    </span><span id="local-6989586621679156913"><span class="annot"><span class="annottext">NodeName -&gt; NodeDef
</span><a href="#local-6989586621679156913"><span class="hs-identifier hs-var">nodeDefLookup</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FoldLike
  (NodeName -&gt; NodeDef)
  GraphState
  GraphState
  (Map NodeName NodeDef)
  (Map NodeName NodeDef)
-&gt; (Map NodeName NodeDef -&gt; NodeName -&gt; NodeDef)
-&gt; BuildT Identity (NodeName -&gt; NodeDef)
forall s (m :: * -&gt; *) r t a b.
MonadState s m =&gt;
FoldLike r s t a b -&gt; (a -&gt; r) -&gt; m r
</span><span class="hs-identifier hs-var">uses</span></span><span> </span><span class="annot"><span class="annottext">FoldLike
  (NodeName -&gt; NodeDef)
  GraphState
  GraphState
  (Map NodeName NodeDef)
  (Map NodeName NodeDef)
Lens' GraphState (Map NodeName NodeDef)
</span><span class="hs-identifier hs-var">renderedNodeDefs</span></span><span> </span><span class="annot"><span class="annottext">((Map NodeName NodeDef -&gt; NodeName -&gt; NodeDef)
 -&gt; BuildT Identity (NodeName -&gt; NodeDef))
-&gt; (Map NodeName NodeDef -&gt; NodeName -&gt; NodeDef)
-&gt; BuildT Identity (NodeName -&gt; NodeDef)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span>
</span><span id="line-168"></span><span>        </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679156912"><span class="annot"><span class="annottext">f :: NodeName -&gt; Maybe NodeDef
</span><a href="#local-6989586621679156912"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679156911"><span class="annot"><span class="annottext">x :: NodeName
</span><a href="#local-6989586621679156911"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Maybe NodeDef -&gt; NodeDef
forall a. a -&gt; Maybe a -&gt; a
</span><span class="hs-identifier hs-var">fromMaybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Char] -&gt; NodeDef
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="annot"><span class="annottext">([Char] -&gt; NodeDef) -&gt; [Char] -&gt; NodeDef
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="hs-string">&quot;no NodeDef found for &quot;</span></span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; [Char] -&gt; [Char]
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">NodeName -&gt; [Char]
forall a. Show a =&gt; a -&gt; [Char]
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156911"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeName -&gt; Maybe NodeDef
</span><a href="#local-6989586621679156912"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156911"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-169"></span><span>        </span><span class="annot"><span class="annottext">((NodeName -&gt; Maybe NodeDef) -&gt; NodeName -&gt; NodeDef)
-&gt; (Map NodeName NodeDef -&gt; NodeName -&gt; Maybe NodeDef)
-&gt; Map NodeName NodeDef
-&gt; NodeName
-&gt; NodeDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">(NodeName -&gt; Map NodeName NodeDef -&gt; Maybe NodeDef)
-&gt; Map NodeName NodeDef -&gt; NodeName -&gt; Maybe NodeDef
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><span class="hs-identifier hs-var">flip</span></span><span> </span><span class="annot"><span class="annottext">NodeName -&gt; Map NodeName NodeDef -&gt; Maybe NodeDef
forall k a. Ord k =&gt; k -&gt; Map k a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Map.lookup</span></span><span>
</span><span id="line-170"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156905"><span class="annot"><span class="annottext">gr :: Graph
</span><a href="#local-6989586621679156905"><span class="hs-identifier hs-var">gr</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156904"><span class="annot"><span class="annottext">nodeMap :: Map NodeName Node
</span><a href="#local-6989586621679156904"><span class="hs-identifier hs-var">nodeMap</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeName -&gt; (NodeName -&gt; NodeDef) -&gt; (Graph, Map NodeName Node)
</span><a href="TensorFlow.Gradient.html#createGraph"><span class="hs-identifier hs-var">createGraph</span></a></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156915"><span class="hs-identifier hs-var">yName</span></a></span><span> </span><span class="annot"><span class="annottext">NodeName -&gt; NodeDef
</span><a href="#local-6989586621679156913"><span class="hs-identifier hs-var">nodeDefLookup</span></a></span><span>
</span><span id="line-171"></span><span>        </span><span id="local-6989586621679156902"><span class="annot"><span class="annottext">xnodes :: [Node]
</span><a href="#local-6989586621679156902"><span class="hs-identifier hs-var hs-var">xnodes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(t a -&gt; Maybe Node) -&gt; [t a] -&gt; [Node]
forall a b. (a -&gt; Maybe b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">mapMaybe</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679156901"><span class="annot"><span class="annottext">x :: t a
</span><a href="#local-6989586621679156901"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Map NodeName Node
</span><a href="#local-6989586621679156904"><span class="hs-identifier hs-var">nodeMap</span></a></span><span> </span><span class="annot"><span class="annottext">Map NodeName Node
-&gt; FoldLike
     (Maybe Node)
     (Map NodeName Node)
     (Map NodeName Node)
     (Maybe Node)
     (Maybe Node)
-&gt; Maybe Node
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeName
-&gt; FoldLike
     (Maybe Node)
     (Map NodeName Node)
     (Map NodeName Node)
     (Maybe Node)
     (Maybe Node)
forall k v. Ord k =&gt; k -&gt; Lens' (Map k v) (Maybe v)
</span><span class="hs-identifier hs-var">at</span></span><span> </span><span class="annot"><span class="annottext">(NodeName
 -&gt; FoldLike
      (Maybe Node)
      (Map NodeName Node)
      (Map NodeName Node)
      (Maybe Node)
      (Maybe Node))
-&gt; (t a -&gt; NodeName)
-&gt; t a
-&gt; FoldLike
     (Maybe Node)
     (Map NodeName Node)
     (Map NodeName Node)
     (Maybe Node)
     (Maybe Node)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Output -&gt; NodeName
</span><span class="hs-identifier hs-var hs-var">outputNodeName</span></span><span> </span><span class="annot"><span class="annottext">(Output -&gt; NodeName) -&gt; (t a -&gt; Output) -&gt; t a -&gt; NodeName
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">t a -&gt; Output
forall (t :: * -&gt; *) a. Rendered t =&gt; t a -&gt; Output
</span><span class="hs-identifier hs-var">renderedOutput</span></span><span> </span><span class="annot"><span class="annottext">(t a
 -&gt; FoldLike
      (Maybe Node)
      (Map NodeName Node)
      (Map NodeName Node)
      (Maybe Node)
      (Maybe Node))
-&gt; t a
-&gt; FoldLike
     (Maybe Node)
     (Map NodeName Node)
     (Map NodeName Node)
     (Maybe Node)
     (Maybe Node)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">t a
</span><a href="#local-6989586621679156901"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[t a]
</span><a href="#local-6989586621679156917"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-172"></span><span>        </span><span class="hs-comment">-- make a set of the nodes reachable from the xnodes</span><span>
</span><span id="line-173"></span><span>        </span><span class="hs-comment">-- The xnodes are not part of this set (unless reachable from another xnode)</span><span>
</span><span id="line-174"></span><span>        </span><span id="local-6989586621679156899"><span class="annot"><span class="annottext">reachableSet :: IntSet
</span><a href="#local-6989586621679156899"><span class="hs-identifier hs-var hs-var">reachableSet</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Node] -&gt; Graph -&gt; IntSet
</span><a href="TensorFlow.Gradient.html#computeReachableSet"><span class="hs-identifier hs-var">computeReachableSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Node]
</span><a href="#local-6989586621679156902"><span class="hs-identifier hs-var">xnodes</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679156905"><span class="hs-identifier hs-var">gr</span></a></span><span>
</span><span id="line-175"></span><span>
</span><span id="line-176"></span><span>    </span><span class="hs-comment">-- Set gradient of y to one.</span><span>
</span><span id="line-177"></span><span>    </span><span class="hs-comment">-- TODO: nicer</span><span>
</span><span id="line-178"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156897"><span class="annot"><span class="annottext">Map Node (PendingGradients a)
</span><a href="#local-6989586621679156897"><span class="hs-identifier hs-var">initPending</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Map.Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#PendingGradients"><span class="hs-identifier hs-type">PendingGradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679156922"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-179"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Node (PendingGradients a)
forall k a. Map k a
</span><span class="hs-identifier hs-var">Map.empty</span></span><span> </span><span class="annot"><span class="annottext">Map Node (PendingGradients a)
-&gt; (Map Node (PendingGradients a) -&gt; Map Node (PendingGradients a))
-&gt; Map Node (PendingGradients a)
forall s t. s -&gt; (s -&gt; t) -&gt; t
</span><span class="hs-operator hs-var">&amp;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Node
-&gt; Lens'
     (Map Node (PendingGradients a)) (Maybe (PendingGradients a))
forall k v. Ord k =&gt; k -&gt; Lens' (Map k v) (Maybe v)
</span><span class="hs-identifier hs-var">at</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map NodeName Node
</span><a href="#local-6989586621679156904"><span class="hs-identifier hs-var">nodeMap</span></a></span><span> </span><span class="annot"><span class="annottext">Map NodeName Node -&gt; NodeName -&gt; Node
forall k a. Ord k =&gt; Map k a -&gt; k -&gt; a
</span><span class="hs-operator hs-var">Map.!</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156915"><span class="hs-identifier hs-var">yName</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-180"></span><span>                                </span><span class="annot"><span class="annottext">LensLike'
  f (Map Node (PendingGradients a)) (Maybe (PendingGradients a))
-&gt; (([Tensor Value a] -&gt; f [Tensor Value a])
    -&gt; Maybe (PendingGradients a) -&gt; f (Maybe (PendingGradients a)))
-&gt; ([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; Map Node (PendingGradients a)
-&gt; f (Map Node (PendingGradients a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">LensLike' f (Maybe (PendingGradients a)) (PendingGradients a)
forall (t :: * -&gt; *) v.
(Monoid (t v), Foldable t) =&gt;
Lens' (Maybe (t v)) (t v)
</span><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-var">nonEmpty</span></a></span><span>
</span><span id="line-181"></span><span>                                </span><span class="annot"><span class="annottext">LensLike' f (Maybe (PendingGradients a)) (PendingGradients a)
-&gt; (([Tensor Value a] -&gt; f [Tensor Value a])
    -&gt; PendingGradients a -&gt; f (PendingGradients a))
-&gt; ([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; Maybe (PendingGradients a)
-&gt; f (Maybe (PendingGradients a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; Lens' (PendingGradients a) (Maybe [Tensor Value a])
forall v. OutputIx -&gt; Lens' (IntMap v) (Maybe v)
</span><a href="TensorFlow.Gradient.html#outputIxAt"><span class="hs-identifier hs-var">outputIxAt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Output -&gt; OutputIx
</span><span class="hs-identifier hs-var hs-var">outputIndex</span></span><span> </span><span class="annot"><span class="annottext">(Output -&gt; OutputIx) -&gt; Output -&gt; OutputIx
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Output
forall (t :: * -&gt; *) a. Rendered t =&gt; t a -&gt; Output
</span><span class="hs-identifier hs-var">renderedOutput</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156916"><span class="hs-identifier hs-var">y'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-182"></span><span>                                </span><span class="annot"><span class="annottext">LensLike' f (PendingGradients a) (Maybe [Tensor Value a])
-&gt; (([Tensor Value a] -&gt; f [Tensor Value a])
    -&gt; Maybe [Tensor Value a] -&gt; f (Maybe [Tensor Value a]))
-&gt; ([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; PendingGradients a
-&gt; f (PendingGradients a)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; Maybe [Tensor Value a] -&gt; f (Maybe [Tensor Value a])
forall (t :: * -&gt; *) v.
(Monoid (t v), Foldable t) =&gt;
Lens' (Maybe (t v)) (t v)
</span><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-var">nonEmpty</span></a></span><span>
</span><span id="line-183"></span><span>                                </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *).
 Identical f =&gt;
 ([Tensor Value a] -&gt; f [Tensor Value a])
 -&gt; Map Node (PendingGradients a)
 -&gt; f (Map Node (PendingGradients a)))
-&gt; [Tensor Value a]
-&gt; Map Node (PendingGradients a)
-&gt; Map Node (PendingGradients a)
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156914"><span class="hs-identifier hs-var">yOne</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-184"></span><span>                                </span><span class="hs-special">)</span><span>
</span><span id="line-185"></span><span>    </span><span class="hs-comment">-- Calculate the gradients of y w.r.t. each node in the graph.</span><span>
</span><span id="line-186"></span><span>    </span><span id="local-6989586621679156892"><span class="annot"><span class="annottext">Map Node (Gradients a)
</span><a href="#local-6989586621679156892"><span class="hs-identifier hs-var">gradientMap</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Graph
-&gt; IntSet
-&gt; Map Node (PendingGradients a)
-&gt; Build (Map Node (Gradients a))
forall a.
GradientCompatible a =&gt;
Graph
-&gt; IntSet
-&gt; Map Node (PendingGradients a)
-&gt; Build (Map Node (Gradients a))
</span><a href="TensorFlow.Gradient.html#graphGrads"><span class="hs-identifier hs-var">graphGrads</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679156905"><span class="hs-identifier hs-var">gr</span></a></span><span> </span><span class="annot"><span class="annottext">IntSet
</span><a href="#local-6989586621679156899"><span class="hs-identifier hs-var">reachableSet</span></a></span><span> </span><span class="annot"><span class="annottext">Map Node (PendingGradients a)
</span><a href="#local-6989586621679156897"><span class="hs-identifier hs-var">initPending</span></a></span><span>
</span><span id="line-187"></span><span>    </span><span class="hs-comment">-- Lookup the gradients for each x.</span><span>
</span><span id="line-188"></span><span>    </span><span class="annot"><span class="annottext">[t a]
-&gt; (t a -&gt; BuildT Identity (Tensor Value a))
-&gt; Build [Tensor Value a]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
t a -&gt; (a -&gt; m b) -&gt; m (t b)
</span><span class="hs-identifier hs-var">forM</span></span><span> </span><span class="annot"><span class="annottext">[t a]
</span><a href="#local-6989586621679156917"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">((t a -&gt; BuildT Identity (Tensor Value a))
 -&gt; Build [Tensor Value a])
-&gt; (t a -&gt; BuildT Identity (Tensor Value a))
-&gt; Build [Tensor Value a]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679156890"><span class="annot"><span class="annottext">x :: t a
</span><a href="#local-6989586621679156890"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-189"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Output</span></span><span> </span><span id="local-6989586621679156888"><span class="annot"><span class="annottext">i :: OutputIx
</span><a href="#local-6989586621679156888"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span id="local-6989586621679156887"><span class="annot"><span class="annottext">xName :: NodeName
</span><a href="#local-6989586621679156887"><span class="hs-identifier hs-var">xName</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">t a -&gt; Output
forall (t :: * -&gt; *) a. Rendered t =&gt; t a -&gt; Output
</span><span class="hs-identifier hs-var">renderedOutput</span></span><span> </span><span class="annot"><span class="annottext">t a
</span><a href="#local-6989586621679156890"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-190"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">BuildT Identity (Tensor Value a)
-&gt; (Tensor Value a -&gt; BuildT Identity (Tensor Value a))
-&gt; Maybe (Tensor Value a)
-&gt; BuildT Identity (Tensor Value a)
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><span class="hs-identifier hs-var">maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; BuildT Identity (Tensor Value a)
forall (m :: * -&gt; *) a.
MonadBuild m =&gt;
Tensor Build a -&gt; m (Tensor Value a)
</span><span class="hs-identifier hs-var">render</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; BuildT Identity (Tensor Value a))
-&gt; Tensor Build a -&gt; BuildT Identity (Tensor Value a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">zerosLike</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Tensor Build a)
-&gt; Tensor Build a -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">t a -&gt; Tensor Build a
forall (t :: * -&gt; *) a.
(ToTensor t, TensorType a) =&gt;
t a -&gt; Tensor Build a
</span><span class="hs-identifier hs-var">toTensor</span></span><span> </span><span class="annot"><span class="annottext">t a
</span><a href="#local-6989586621679156890"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; BuildT Identity (Tensor Value a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><span class="hs-identifier hs-var">return</span></span><span> </span><span class="annot"><span class="annottext">(Maybe (Tensor Value a) -&gt; BuildT Identity (Tensor Value a))
-&gt; Maybe (Tensor Value a) -&gt; BuildT Identity (Tensor Value a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-191"></span><span>            </span><span id="local-6989586621679156884"><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156884"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Map NodeName Node
</span><a href="#local-6989586621679156904"><span class="hs-identifier hs-var">nodeMap</span></a></span><span> </span><span class="annot"><span class="annottext">Map NodeName Node
-&gt; FoldLike
     (Maybe Node)
     (Map NodeName Node)
     (Map NodeName Node)
     (Maybe Node)
     (Maybe Node)
-&gt; Maybe Node
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">NodeName -&gt; Lens' (Map NodeName Node) (Maybe Node)
forall k v. Ord k =&gt; k -&gt; Lens' (Map k v) (Maybe v)
</span><span class="hs-identifier hs-var">at</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156887"><span class="hs-identifier hs-var">xName</span></a></span><span>
</span><span id="line-192"></span><span>            </span><span class="annot"><span class="annottext">Map Node (Gradients a)
</span><a href="#local-6989586621679156892"><span class="hs-identifier hs-var">gradientMap</span></a></span><span> </span><span class="annot"><span class="annottext">Map Node (Gradients a)
-&gt; FoldLike
     (Maybe (Tensor Value a))
     (Map Node (Gradients a))
     (Map Node (Gradients a))
     (Maybe (Tensor Value a))
     (Maybe (Tensor Value a))
-&gt; Maybe (Tensor Value a)
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">Node -&gt; Lens' (Map Node (Gradients a)) (Maybe (Gradients a))
forall k v. Ord k =&gt; k -&gt; Lens' (Map k v) (Maybe v)
</span><span class="hs-identifier hs-var">at</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156884"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">LensLike'
  (Constant (Maybe (Tensor Value a)))
  (Map Node (Gradients a))
  (Maybe (Gradients a))
-&gt; ((Maybe (Tensor Value a)
     -&gt; Constant (Maybe (Tensor Value a)) (Maybe (Tensor Value a)))
    -&gt; Maybe (Gradients a)
    -&gt; Constant (Maybe (Tensor Value a)) (Maybe (Gradients a)))
-&gt; FoldLike
     (Maybe (Tensor Value a))
     (Map Node (Gradients a))
     (Map Node (Gradients a))
     (Maybe (Tensor Value a))
     (Maybe (Tensor Value a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">LensLike'
  (Constant (Maybe (Tensor Value a)))
  (Maybe (Gradients a))
  (Gradients a)
forall (t :: * -&gt; *) v.
(Monoid (t v), Foldable t) =&gt;
Lens' (Maybe (t v)) (t v)
</span><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-var">nonEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">LensLike'
  (Constant (Maybe (Tensor Value a)))
  (Maybe (Gradients a))
  (Gradients a)
-&gt; ((Maybe (Tensor Value a)
     -&gt; Constant (Maybe (Tensor Value a)) (Maybe (Tensor Value a)))
    -&gt; Gradients a -&gt; Constant (Maybe (Tensor Value a)) (Gradients a))
-&gt; (Maybe (Tensor Value a)
    -&gt; Constant (Maybe (Tensor Value a)) (Maybe (Tensor Value a)))
-&gt; Maybe (Gradients a)
-&gt; Constant (Maybe (Tensor Value a)) (Maybe (Gradients a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; Lens' (Gradients a) (Maybe (Tensor Value a))
forall v. OutputIx -&gt; Lens' (IntMap v) (Maybe v)
</span><a href="TensorFlow.Gradient.html#outputIxAt"><span class="hs-identifier hs-var">outputIxAt</span></a></span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156888"><span class="hs-identifier hs-var">i</span></a></span><span>
</span><span id="line-193"></span><span>
</span><span id="line-194"></span><span class="hs-comment">-- | Compute a set of nodes reachable from the start nodes</span><span>
</span><span id="line-195"></span><span class="hs-comment">--</span><span>
</span><span id="line-196"></span><span class="hs-comment">-- the start nodes are excluded, unless reachable from another start node</span><span>
</span><span id="line-197"></span><span class="annot"><a href="TensorFlow.Gradient.html#computeReachableSet"><span class="hs-identifier hs-type">computeReachableSet</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IntSet.IntSet</span></span><span>
</span><span id="line-198"></span><span id="computeReachableSet"><span class="annot"><span class="annottext">computeReachableSet :: [Node] -&gt; Graph -&gt; IntSet
</span><a href="TensorFlow.Gradient.html#computeReachableSet"><span class="hs-identifier hs-var hs-var">computeReachableSet</span></a></span></span><span> </span><span id="local-6989586621679156883"><span class="annot"><span class="annottext">vs :: [Node]
</span><a href="#local-6989586621679156883"><span class="hs-identifier hs-var">vs</span></a></span></span><span> </span><span id="local-6989586621679156882"><span class="annot"><span class="annottext">g :: Graph
</span><a href="#local-6989586621679156882"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-199"></span><span>  </span><span class="annot"><span class="annottext">[Node] -&gt; IntSet
</span><span class="hs-identifier hs-var">IntSet.fromList</span></span><span> </span><span class="annot"><span class="annottext">([Node] -&gt; IntSet) -&gt; [Node] -&gt; IntSet
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(Tree Node -&gt; [Node]) -&gt; [Tree Node] -&gt; [Node]
forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
</span><span class="hs-identifier hs-var">concatMap</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Node -&gt; [Node] -&gt; [Node]
forall a. Node -&gt; [a] -&gt; [a]
</span><span class="hs-identifier hs-var">drop</span></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">([Node] -&gt; [Node]) -&gt; (Tree Node -&gt; [Node]) -&gt; Tree Node -&gt; [Node]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Tree Node -&gt; [Node]
forall a. Tree a -&gt; [a]
</span><span class="hs-identifier hs-var">FGL.preorder</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Node] -&gt; Graph -&gt; [Tree Node]
forall (gr :: * -&gt; * -&gt; *) a b.
Graph gr =&gt;
[Node] -&gt; gr a b -&gt; [Tree Node]
</span><span class="hs-identifier hs-var">FGL.dff</span></span><span> </span><span class="annot"><span class="annottext">[Node]
</span><a href="#local-6989586621679156883"><span class="hs-identifier hs-var">vs</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679156882"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-200"></span><span>
</span><span id="line-201"></span><span id="local-6989586621679157404"><span class="annot"><a href="TensorFlow.Gradient.html#outputIxAt"><span class="hs-identifier hs-type">outputIxAt</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Lens'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">IntMap.IntMap</span></span><span> </span><span class="annot"><a href="#local-6989586621679157404"><span class="hs-identifier hs-type">v</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="annot"><a href="#local-6989586621679157404"><span class="hs-identifier hs-type">v</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-202"></span><span id="outputIxAt"><span class="annot"><span class="annottext">outputIxAt :: OutputIx -&gt; Lens' (IntMap v) (Maybe v)
</span><a href="TensorFlow.Gradient.html#outputIxAt"><span class="hs-identifier hs-var hs-var">outputIxAt</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Node -&gt; LensLike' f (IntMap v) (Maybe v)
forall v. Node -&gt; Lens' (IntMap v) (Maybe v)
</span><span class="hs-identifier hs-var">intAt</span></span><span> </span><span class="annot"><span class="annottext">(Node -&gt; LensLike' f (IntMap v) (Maybe v))
-&gt; (OutputIx -&gt; Node)
-&gt; OutputIx
-&gt; LensLike' f (IntMap v) (Maybe v)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; Node
</span><span class="hs-identifier hs-var hs-var">unOutputIx</span></span><span>
</span><span id="line-203"></span><span>
</span><span id="line-204"></span><span class="hs-comment">-- | Incomplete gradients of a node's outputs.</span><span>
</span><span id="line-205"></span><span class="hs-comment">--</span><span>
</span><span id="line-206"></span><span class="hs-comment">-- The lists represent partial sums. The key is an OutputIx sans newtype.</span><span>
</span><span id="line-207"></span><span class="hs-keyword">type</span><span> </span><span id="PendingGradients"><span class="annot"><a href="TensorFlow.Gradient.html#PendingGradients"><span class="hs-identifier hs-var">PendingGradients</span></a></span></span><span> </span><span id="local-6989586621679156875"><span class="annot"><a href="#local-6989586621679156875"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IntMap.IntMap</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Value</span></span><span> </span><span class="annot"><a href="#local-6989586621679156875"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-208"></span><span>
</span><span id="line-209"></span><span class="hs-comment">-- | Gradients of a node's outputs. The key is an OutputIx sans newtype.</span><span>
</span><span id="line-210"></span><span class="hs-comment">-- TODO: precache the rendering?</span><span>
</span><span id="line-211"></span><span class="hs-keyword">type</span><span> </span><span id="Gradients"><span class="annot"><a href="TensorFlow.Gradient.html#Gradients"><span class="hs-identifier hs-var">Gradients</span></a></span></span><span> </span><span id="local-6989586621679156874"><span class="annot"><a href="#local-6989586621679156874"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IntMap.IntMap</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Value</span></span><span> </span><span class="annot"><a href="#local-6989586621679156874"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-212"></span><span>
</span><span id="line-213"></span><span class="hs-comment">-- | Graph of TensorFlow operations.</span><span>
</span><span id="line-214"></span><span class="hs-keyword">type</span><span> </span><span id="Graph"><span class="annot"><a href="TensorFlow.Gradient.html#Graph"><span class="hs-identifier hs-var">Graph</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Gr</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#EdgeLabel"><span class="hs-identifier hs-type">EdgeLabel</span></a></span><span>
</span><span id="line-215"></span><span>
</span><span id="line-216"></span><span class="hs-comment">-- | Data associated with an edge.</span><span>
</span><span id="line-217"></span><span class="hs-comment">--</span><span>
</span><span id="line-218"></span><span class="hs-comment">-- Pair of</span><span>
</span><span id="line-219"></span><span class="hs-comment">--   1. Output index of a tensor from the source node.</span><span>
</span><span id="line-220"></span><span class="hs-comment">--   2. Input index that the tensor connects to on the destination node.</span><span>
</span><span id="line-221"></span><span class="hs-keyword">type</span><span> </span><span id="EdgeLabel"><span class="annot"><a href="TensorFlow.Gradient.html#EdgeLabel"><span class="hs-identifier hs-var">EdgeLabel</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span class="hs-special">)</span><span>
</span><span id="line-222"></span><span>
</span><span id="line-223"></span><span>
</span><span id="line-224"></span><span class="hs-comment">-- | State used for calculating gradients.</span><span>
</span><span id="line-225"></span><span class="hs-keyword">data</span><span> </span><span id="GradientsState"><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-var">GradientsState</span></a></span></span><span> </span><span id="local-6989586621679157357"><span class="annot"><a href="#local-6989586621679157357"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="GradientsState"><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-var">GradientsState</span></a></span></span><span>
</span><span id="line-226"></span><span>                      </span><span class="hs-special">{</span><span> </span><span id="_gradientsPending"><span class="annot"><span class="annottext">GradientsState a -&gt; Map Node (PendingGradients a)
</span><a href="TensorFlow.Gradient.html#_gradientsPending"><span class="hs-identifier hs-var hs-var">_gradientsPending</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#PendingGradients"><span class="hs-identifier hs-type">PendingGradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157357"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-227"></span><span>                      </span><span class="hs-special">,</span><span> </span><span id="_gradientsResult"><span class="annot"><span class="annottext">GradientsState a -&gt; Map Node (Gradients a)
</span><a href="TensorFlow.Gradient.html#_gradientsResult"><span class="hs-identifier hs-var hs-var">_gradientsResult</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#Gradients"><span class="hs-identifier hs-type">Gradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157357"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-228"></span><span>                      </span><span class="hs-special">}</span><span>
</span><span id="line-229"></span><span>
</span><span id="line-230"></span><span id="local-6989586621679157304"><span class="annot"><a href="TensorFlow.Gradient.html#gradientsPending"><span class="hs-identifier hs-type">gradientsPending</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Lens'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157304"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#PendingGradients"><span class="hs-identifier hs-type">PendingGradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157304"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span></span><span>
</span><span id="line-231"></span><span id="gradientsPending"><span class="annot"><span class="annottext">gradientsPending :: LensLike' f (GradientsState a) (Map Node (PendingGradients a))
</span><a href="TensorFlow.Gradient.html#gradientsPending"><span class="hs-identifier hs-var hs-var">gradientsPending</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(GradientsState a -&gt; Map Node (PendingGradients a))
-&gt; (GradientsState a
    -&gt; Map Node (PendingGradients a) -&gt; GradientsState a)
-&gt; Lens
     (GradientsState a)
     (GradientsState a)
     (Map Node (PendingGradients a))
     (Map Node (PendingGradients a))
forall s a b t. (s -&gt; a) -&gt; (s -&gt; b -&gt; t) -&gt; Lens s t a b
</span><span class="hs-identifier hs-var">lens</span></span><span> </span><span class="annot"><span class="annottext">GradientsState a -&gt; Map Node (PendingGradients a)
forall a. GradientsState a -&gt; Map Node (PendingGradients a)
</span><a href="TensorFlow.Gradient.html#_gradientsPending"><span class="hs-identifier hs-var hs-var">_gradientsPending</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679156869"><span class="annot"><span class="annottext">x :: GradientsState a
</span><a href="#local-6989586621679156869"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679156868"><span class="annot"><span class="annottext">y :: Map Node (PendingGradients a)
</span><a href="#local-6989586621679156868"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156869"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">_gradientsPending :: Map Node (PendingGradients a)
</span><a href="TensorFlow.Gradient.html#_gradientsPending"><span class="hs-identifier hs-var">_gradientsPending</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Node (PendingGradients a)
</span><a href="#local-6989586621679156868"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-232"></span><span>
</span><span id="line-233"></span><span id="local-6989586621679157320"><span class="annot"><a href="TensorFlow.Gradient.html#gradientsResult"><span class="hs-identifier hs-type">gradientsResult</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Lens'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157320"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#Gradients"><span class="hs-identifier hs-type">Gradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157320"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span></span><span>
</span><span id="line-234"></span><span id="gradientsResult"><span class="annot"><span class="annottext">gradientsResult :: LensLike' f (GradientsState a) (Map Node (Gradients a))
</span><a href="TensorFlow.Gradient.html#gradientsResult"><span class="hs-identifier hs-var hs-var">gradientsResult</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(GradientsState a -&gt; Map Node (Gradients a))
-&gt; (GradientsState a -&gt; Map Node (Gradients a) -&gt; GradientsState a)
-&gt; Lens
     (GradientsState a)
     (GradientsState a)
     (Map Node (Gradients a))
     (Map Node (Gradients a))
forall s a b t. (s -&gt; a) -&gt; (s -&gt; b -&gt; t) -&gt; Lens s t a b
</span><span class="hs-identifier hs-var">lens</span></span><span> </span><span class="annot"><span class="annottext">GradientsState a -&gt; Map Node (Gradients a)
forall a. GradientsState a -&gt; Map Node (Gradients a)
</span><a href="TensorFlow.Gradient.html#_gradientsResult"><span class="hs-identifier hs-var hs-var">_gradientsResult</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679156866"><span class="annot"><span class="annottext">x :: GradientsState a
</span><a href="#local-6989586621679156866"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679156865"><span class="annot"><span class="annottext">y :: Map Node (Gradients a)
</span><a href="#local-6989586621679156865"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156866"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">_gradientsResult :: Map Node (Gradients a)
</span><a href="TensorFlow.Gradient.html#_gradientsResult"><span class="hs-identifier hs-var">_gradientsResult</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Node (Gradients a)
</span><a href="#local-6989586621679156865"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-235"></span><span>
</span><span id="line-236"></span><span>
</span><span id="line-237"></span><span class="hs-comment">-- TODO(fmayle): Use something like Data.List.Safe.</span><span>
</span><span id="line-238"></span><span class="hs-comment">-- | Safe version of (!!).</span><span>
</span><span id="line-239"></span><span id="local-6989586621679157351"><span class="annot"><a href="TensorFlow.Gradient.html#safeIndex"><span class="hs-identifier hs-type">safeIndex</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679157351"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="annot"><a href="#local-6989586621679157351"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-240"></span><span class="hs-identifier">_</span><span>      </span><span id="safeIndex"><span class="annot"><span class="annottext">safeIndex :: [a] -&gt; Node -&gt; Maybe a
</span><a href="TensorFlow.Gradient.html#safeIndex"><span class="hs-operator hs-var hs-var">`safeIndex`</span></a></span></span><span> </span><span id="local-6989586621679156863"><span class="annot"><span class="annottext">n :: Node
</span><a href="#local-6989586621679156863"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156863"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Node -&gt; Node -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-241"></span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span class="annot"><a href="TensorFlow.Gradient.html#safeIndex"><span class="hs-operator hs-var">`safeIndex`</span></a></span><span> </span><span class="hs-identifier">_</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-242"></span><span class="hs-special">(</span><span id="local-6989586621679156861"><span class="annot"><span class="annottext">x :: a
</span><a href="#local-6989586621679156861"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="hs-identifier">_</span><span class="hs-special">)</span><span>  </span><span class="annot"><a href="TensorFlow.Gradient.html#safeIndex"><span class="hs-operator hs-var">`safeIndex`</span></a></span><span> </span><span class="hs-number">0</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156861"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-243"></span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679156860"><span class="annot"><span class="annottext">xs :: [a]
</span><a href="#local-6989586621679156860"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#safeIndex"><span class="hs-operator hs-var">`safeIndex`</span></a></span><span> </span><span id="local-6989586621679156859"><span class="annot"><span class="annottext">n :: Node
</span><a href="#local-6989586621679156859"><span class="hs-identifier hs-var">n</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679156860"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; Node -&gt; Maybe a
forall a. [a] -&gt; Node -&gt; Maybe a
</span><a href="TensorFlow.Gradient.html#safeIndex"><span class="hs-operator hs-var">`safeIndex`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156859"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Node -&gt; Node -&gt; Node
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-glyph hs-var">-</span></span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-244"></span><span>
</span><span id="line-245"></span><span class="hs-comment">-- Copy of http://hackage.haskell.org/package/lens-3.9.0.2/docs/Control-Lens-Iso.html#v%3anon</span><span>
</span><span id="line-246"></span><span id="local-6989586621679157333"><span class="annot"><a href="TensorFlow.Gradient.html#anon"><span class="hs-identifier hs-type">anon</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679157333"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679157333"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Lens'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="annot"><a href="#local-6989586621679157333"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><a href="#local-6989586621679157333"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-247"></span><span id="anon"><span class="annot"><span class="annottext">anon :: a -&gt; (a -&gt; Bool) -&gt; Lens' (Maybe a) a
</span><a href="TensorFlow.Gradient.html#anon"><span class="hs-identifier hs-var hs-var">anon</span></a></span></span><span> </span><span id="local-6989586621679156857"><span class="annot"><span class="annottext">a :: a
</span><a href="#local-6989586621679156857"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679156856"><span class="annot"><span class="annottext">p :: a -&gt; Bool
</span><a href="#local-6989586621679156856"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Resetter (Maybe a) (f (Maybe a)) a (f a)
-&gt; (a -&gt; f a) -&gt; Maybe a -&gt; f (Maybe a)
forall s t a b. Resetter s t a b -&gt; (a -&gt; b) -&gt; s -&gt; t
</span><span class="hs-identifier hs-var">under</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Maybe a -&gt; a) -&gt; (a -&gt; Maybe a) -&gt; Adapter (Maybe a) (Maybe a) a a
forall s a b t. (s -&gt; a) -&gt; (b -&gt; t) -&gt; Adapter s t a b
</span><span class="hs-identifier hs-var">adapter</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a -&gt; a
forall a. a -&gt; Maybe a -&gt; a
</span><span class="hs-identifier hs-var">fromMaybe</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156857"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a
</span><a href="#local-6989586621679156855"><span class="hs-identifier hs-var">go</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-248"></span><span>  </span><span id="local-6989586621679156855"><span class="annot"><span class="annottext">go :: a -&gt; Maybe a
</span><a href="#local-6989586621679156855"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679156854"><span class="annot"><span class="annottext">b :: a
</span><a href="#local-6989586621679156854"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a -&gt; Bool
</span><a href="#local-6989586621679156856"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156854"><span class="hs-identifier hs-var">b</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-249"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">otherwise</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156854"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-250"></span><span>
</span><span id="line-251"></span><span id="local-6989586621679156992"><span class="annot"><a href="TensorFlow.Gradient.html#non"><span class="hs-identifier hs-type">non</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Eq</span></span><span> </span><span class="annot"><a href="#local-6989586621679156992"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679156992"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Lens'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="annot"><a href="#local-6989586621679156992"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><a href="#local-6989586621679156992"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-252"></span><span id="non"><span class="annot"><span class="annottext">non :: a -&gt; Lens' (Maybe a) a
</span><a href="TensorFlow.Gradient.html#non"><span class="hs-identifier hs-var hs-var">non</span></a></span></span><span> </span><span id="local-6989586621679156852"><span class="annot"><span class="annottext">a :: a
</span><a href="#local-6989586621679156852"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; (a -&gt; Bool) -&gt; Lens' (Maybe a) a
forall a. a -&gt; (a -&gt; Bool) -&gt; Lens' (Maybe a) a
</span><a href="TensorFlow.Gradient.html#anon"><span class="hs-identifier hs-var">anon</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156852"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156852"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span class="hs-special">)</span><span>
</span><span id="line-253"></span><span>
</span><span id="line-254"></span><span class="hs-comment">-- | Lens that defaults Nothing to mempty.</span><span>
</span><span id="line-255"></span><span id="local-6989586621679157406"><span id="local-6989586621679157407"><span class="annot"><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-type">nonEmpty</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Monoid</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679157407"><span class="hs-identifier hs-type">t</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157406"><span class="hs-identifier hs-type">v</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Foldable</span></span><span> </span><span class="annot"><a href="#local-6989586621679157407"><span class="hs-identifier hs-type">t</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Lens'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679157407"><span class="hs-identifier hs-type">t</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157406"><span class="hs-identifier hs-type">v</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679157407"><span class="hs-identifier hs-type">t</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157406"><span class="hs-identifier hs-type">v</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-256"></span><span id="nonEmpty"><span class="annot"><span class="annottext">nonEmpty :: Lens' (Maybe (t v)) (t v)
</span><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-var hs-var">nonEmpty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">t v -&gt; (t v -&gt; Bool) -&gt; Lens' (Maybe (t v)) (t v)
forall a. a -&gt; (a -&gt; Bool) -&gt; Lens' (Maybe a) a
</span><a href="TensorFlow.Gradient.html#anon"><span class="hs-identifier hs-var">anon</span></a></span><span> </span><span class="annot"><span class="annottext">t v
forall a. Monoid a =&gt; a
</span><span class="hs-identifier hs-var">mempty</span></span><span> </span><span class="annot"><span class="annottext">t v -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><span class="hs-identifier hs-var">null</span></span><span>
</span><span id="line-257"></span><span>
</span><span id="line-258"></span><span class="hs-comment">-- TODO: strictness (e.g., foldlM')</span><span>
</span><span id="line-259"></span><span>
</span><span id="line-260"></span><span class="hs-comment">-- | Calculate the gradients for every node in a graph.</span><span>
</span><span id="line-261"></span><span class="annot"><a href="TensorFlow.Gradient.html#graphGrads"><span class="hs-identifier hs-type">graphGrads</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679157396"><span class="annot"><a href="#local-6989586621679157396"><span class="hs-identifier hs-type">a</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientCompatible"><span class="hs-identifier hs-type">GradientCompatible</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157396"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-262"></span><span>           </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span>
</span><span id="line-263"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IntSet.IntSet</span></span><span>
</span><span id="line-264"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#PendingGradients"><span class="hs-identifier hs-type">PendingGradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157396"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-265"></span><span>           </span><span class="hs-comment">-- ^ Initial gradients (usually just 1 for the node of interest).</span><span>
</span><span id="line-266"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#Gradients"><span class="hs-identifier hs-type">Gradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157396"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-267"></span><span id="graphGrads"><span class="annot"><span class="annottext">graphGrads :: Graph
-&gt; IntSet
-&gt; Map Node (PendingGradients a)
-&gt; Build (Map Node (Gradients a))
</span><a href="TensorFlow.Gradient.html#graphGrads"><span class="hs-identifier hs-var hs-var">graphGrads</span></a></span></span><span> </span><span id="local-6989586621679156850"><span class="annot"><span class="annottext">gr :: Graph
</span><a href="#local-6989586621679156850"><span class="hs-identifier hs-var">gr</span></a></span></span><span> </span><span id="local-6989586621679156849"><span class="annot"><span class="annottext">reachableSet :: IntSet
</span><a href="#local-6989586621679156849"><span class="hs-identifier hs-var">reachableSet</span></a></span></span><span> </span><span id="local-6989586621679156848"><span class="annot"><span class="annottext">initPending :: Map Node (PendingGradients a)
</span><a href="#local-6989586621679156848"><span class="hs-identifier hs-var">initPending</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FoldLike
  (Map Node (Gradients a))
  (GradientsState a)
  (GradientsState a)
  (Map Node (Gradients a))
  (Map Node (Gradients a))
-&gt; GradientsState a -&gt; Map Node (Gradients a)
forall a s t b. FoldLike a s t a b -&gt; s -&gt; a
</span><span class="hs-identifier hs-var">view</span></span><span> </span><span class="annot"><span class="annottext">FoldLike
  (Map Node (Gradients a))
  (GradientsState a)
  (GradientsState a)
  (Map Node (Gradients a))
  (Map Node (Gradients a))
forall a. Lens' (GradientsState a) (Map Node (Gradients a))
</span><a href="TensorFlow.Gradient.html#gradientsResult"><span class="hs-identifier hs-var">gradientsResult</span></a></span><span> </span><span class="annot"><span class="annottext">(GradientsState a -&gt; Map Node (Gradients a))
-&gt; BuildT Identity (GradientsState a)
-&gt; Build (Map Node (Gradients a))
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">(GradientsState a -&gt; Node -&gt; BuildT Identity (GradientsState a))
-&gt; GradientsState a -&gt; [Node] -&gt; BuildT Identity (GradientsState a)
forall (t :: * -&gt; *) (m :: * -&gt; *) b a.
(Foldable t, Monad m) =&gt;
(b -&gt; a -&gt; m b) -&gt; b -&gt; t a -&gt; m b
</span><span class="hs-identifier hs-var">foldlM</span></span><span> </span><span class="annot"><span class="annottext">GradientsState a -&gt; Node -&gt; BuildT Identity (GradientsState a)
</span><a href="#local-6989586621679156846"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156845"><span class="hs-identifier hs-var">initState</span></a></span><span> </span><span class="annot"><span class="annottext">[Node]
</span><a href="#local-6989586621679156844"><span class="hs-identifier hs-var">nodeOrder</span></a></span><span>
</span><span id="line-268"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-269"></span><span>    </span><span id="local-6989586621679156845"><span class="annot"><span class="annottext">initState :: GradientsState a
</span><a href="#local-6989586621679156845"><span class="hs-identifier hs-var hs-var">initState</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Node (PendingGradients a)
-&gt; Map Node (Gradients a) -&gt; GradientsState a
forall a.
Map Node (PendingGradients a)
-&gt; Map Node (Gradients a) -&gt; GradientsState a
</span><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-var">GradientsState</span></a></span><span> </span><span class="annot"><span class="annottext">Map Node (PendingGradients a)
</span><a href="#local-6989586621679156848"><span class="hs-identifier hs-var">initPending</span></a></span><span> </span><span class="annot"><span class="annottext">Map Node (Gradients a)
forall k a. Map k a
</span><span class="hs-identifier hs-var">Map.empty</span></span><span>
</span><span id="line-270"></span><span>    </span><span class="hs-comment">-- Reverse topological sort.</span><span>
</span><span id="line-271"></span><span>    </span><span id="local-6989586621679156844"><span class="annot"><span class="annottext">nodeOrder :: [Node]
</span><a href="#local-6989586621679156844"><span class="hs-identifier hs-var hs-var">nodeOrder</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Node]
forall (gr :: * -&gt; * -&gt; *) a b. Graph gr =&gt; gr a b -&gt; [Node]
</span><span class="hs-identifier hs-var">FGL.topsort</span></span><span> </span><span class="annot"><span class="annottext">(Graph -&gt; [Node]) -&gt; (Graph -&gt; Graph) -&gt; Graph -&gt; [Node]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Graph -&gt; Graph
forall (gr :: * -&gt; * -&gt; *) a b. DynGraph gr =&gt; gr a b -&gt; gr a b
</span><span class="hs-identifier hs-var">FGL.grev</span></span><span> </span><span class="annot"><span class="annottext">(Graph -&gt; [Node]) -&gt; Graph -&gt; [Node]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679156850"><span class="hs-identifier hs-var">gr</span></a></span><span>
</span><span id="line-272"></span><span>    </span><span class="annot"><a href="#local-6989586621679156846"><span class="hs-identifier hs-type">go</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157396"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157396"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-273"></span><span>    </span><span id="local-6989586621679156846"><span class="annot"><span class="annottext">go :: GradientsState a -&gt; Node -&gt; BuildT Identity (GradientsState a)
</span><a href="#local-6989586621679156846"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679156841"><span class="annot"><span class="annottext">state :: GradientsState a
</span><a href="#local-6989586621679156841"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span id="local-6989586621679156840"><span class="annot"><span class="annottext">node :: Node
</span><a href="#local-6989586621679156840"><span class="hs-identifier hs-var">node</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-274"></span><span>        </span><span class="hs-comment">-- Aggregate the accumulated gradients for this node.</span><span>
</span><span id="line-275"></span><span>        </span><span id="local-6989586621679156839"><span class="annot"><span class="annottext">Gradients a
</span><a href="#local-6989586621679156839"><span class="hs-identifier hs-var">outputGrads</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-276"></span><span>                </span><span class="annot"><span class="annottext">PendingGradients a -&gt; Build (Gradients a)
forall a.
GradientCompatible a =&gt;
PendingGradients a -&gt; Build (Gradients a)
</span><a href="TensorFlow.Gradient.html#sumPendingGradient"><span class="hs-identifier hs-var">sumPendingGradient</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156841"><span class="hs-identifier hs-var">state</span></a></span><span> </span><span class="annot"><span class="annottext">GradientsState a
-&gt; FoldLike
     (PendingGradients a)
     (GradientsState a)
     (GradientsState a)
     (PendingGradients a)
     (PendingGradients a)
-&gt; PendingGradients a
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">LensLike'
  (Constant (PendingGradients a))
  (GradientsState a)
  (Map Node (PendingGradients a))
forall a. Lens' (GradientsState a) (Map Node (PendingGradients a))
</span><a href="TensorFlow.Gradient.html#gradientsPending"><span class="hs-identifier hs-var">gradientsPending</span></a></span><span> </span><span class="annot"><span class="annottext">LensLike'
  (Constant (PendingGradients a))
  (GradientsState a)
  (Map Node (PendingGradients a))
-&gt; ((PendingGradients a
     -&gt; Constant (PendingGradients a) (PendingGradients a))
    -&gt; Map Node (PendingGradients a)
    -&gt; Constant (PendingGradients a) (Map Node (PendingGradients a)))
-&gt; FoldLike
     (PendingGradients a)
     (GradientsState a)
     (GradientsState a)
     (PendingGradients a)
     (PendingGradients a)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Node
-&gt; Lens'
     (Map Node (PendingGradients a)) (Maybe (PendingGradients a))
forall k v. Ord k =&gt; k -&gt; Lens' (Map k v) (Maybe v)
</span><span class="hs-identifier hs-var">at</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156840"><span class="hs-identifier hs-var">node</span></a></span><span> </span><span class="annot"><span class="annottext">LensLike'
  (Constant (PendingGradients a))
  (Map Node (PendingGradients a))
  (Maybe (PendingGradients a))
-&gt; ((PendingGradients a
     -&gt; Constant (PendingGradients a) (PendingGradients a))
    -&gt; Maybe (PendingGradients a)
    -&gt; Constant (PendingGradients a) (Maybe (PendingGradients a)))
-&gt; (PendingGradients a
    -&gt; Constant (PendingGradients a) (PendingGradients a))
-&gt; Map Node (PendingGradients a)
-&gt; Constant (PendingGradients a) (Map Node (PendingGradients a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">(PendingGradients a
 -&gt; Constant (PendingGradients a) (PendingGradients a))
-&gt; Maybe (PendingGradients a)
-&gt; Constant (PendingGradients a) (Maybe (PendingGradients a))
forall (t :: * -&gt; *) v.
(Monoid (t v), Foldable t) =&gt;
Lens' (Maybe (t v)) (t v)
</span><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-var">nonEmpty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-277"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Gradients a -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><span class="hs-identifier hs-var">null</span></span><span> </span><span class="annot"><span class="annottext">Gradients a
</span><a href="#local-6989586621679156839"><span class="hs-identifier hs-var">outputGrads</span></a></span><span>
</span><span id="line-278"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">GradientsState a -&gt; BuildT Identity (GradientsState a)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156841"><span class="hs-identifier hs-var">state</span></a></span><span>
</span><span id="line-279"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-280"></span><span>              </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156837"><span class="annot"><span class="annottext">nextState :: GradientsState a
</span><a href="#local-6989586621679156837"><span class="hs-identifier hs-var hs-var">nextState</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156841"><span class="hs-identifier hs-var">state</span></a></span><span> </span><span class="annot"><span class="annottext">GradientsState a
-&gt; (GradientsState a -&gt; GradientsState a) -&gt; GradientsState a
forall s t. s -&gt; (s -&gt; t) -&gt; t
</span><span class="hs-operator hs-var">&amp;</span></span><span> </span><span class="annot"><span class="annottext">forall a. Lens' (GradientsState a) (Map Node (Gradients a))
forall (f :: * -&gt; *).
Identical f =&gt;
LensLike' f (GradientsState a) (Map Node (Gradients a))
</span><a href="TensorFlow.Gradient.html#gradientsResult"><span class="hs-identifier hs-var">gradientsResult</span></a></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *).
 Identical f =&gt;
 LensLike' f (GradientsState a) (Map Node (Gradients a)))
-&gt; (Map Node (Gradients a) -&gt; Map Node (Gradients a))
-&gt; GradientsState a
-&gt; GradientsState a
forall s t a b. Setter s t a b -&gt; (a -&gt; b) -&gt; s -&gt; t
</span><span class="hs-operator hs-var">%~</span></span><span> </span><span class="annot"><span class="annottext">Node
-&gt; Gradients a -&gt; Map Node (Gradients a) -&gt; Map Node (Gradients a)
forall k a. Ord k =&gt; k -&gt; a -&gt; Map k a -&gt; Map k a
</span><span class="hs-identifier hs-var">Map.insert</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156840"><span class="hs-identifier hs-var">node</span></a></span><span> </span><span class="annot"><span class="annottext">Gradients a
</span><a href="#local-6989586621679156839"><span class="hs-identifier hs-var">outputGrads</span></a></span><span>
</span><span id="line-281"></span><span>              </span><span class="hs-comment">-- Only consider nodes that are reachable from the inputs to</span><span>
</span><span id="line-282"></span><span>              </span><span class="hs-comment">-- avoid calculating gradients that won't be used.</span><span>
</span><span id="line-283"></span><span>              </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156840"><span class="hs-identifier hs-var">node</span></a></span><span> </span><span class="annot"><span class="annottext">Node -&gt; IntSet -&gt; Bool
</span><span class="hs-operator hs-var">`IntSet.member`</span></span><span> </span><span class="annot"><span class="annottext">IntSet
</span><a href="#local-6989586621679156849"><span class="hs-identifier hs-var">reachableSet</span></a></span><span>
</span><span id="line-284"></span><span>                </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-285"></span><span>                  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156834"><span class="annot"><span class="annottext">ctx :: Context NodeDef EdgeLabel
</span><a href="#local-6989586621679156834"><span class="hs-identifier hs-var hs-var">ctx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; Node -&gt; Context NodeDef EdgeLabel
forall (gr :: * -&gt; * -&gt; *) a b.
Graph gr =&gt;
gr a b -&gt; Node -&gt; Context a b
</span><span class="hs-identifier hs-var">FGL.context</span></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679156850"><span class="hs-identifier hs-var">gr</span></a></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156840"><span class="hs-identifier hs-var">node</span></a></span><span>
</span><span id="line-286"></span><span>                  </span><span id="local-6989586621679156832"><span class="annot"><span class="annottext">[Maybe (Tensor Value a)]
</span><a href="#local-6989586621679156832"><span class="hs-identifier hs-var">inputGrads</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Context NodeDef EdgeLabel
-&gt; Gradients a -&gt; Graph -&gt; Build [Maybe (Tensor Value a)]
forall a.
GradientCompatible a =&gt;
Context NodeDef EdgeLabel
-&gt; Gradients a -&gt; Graph -&gt; Build [Maybe (Tensor Value a)]
</span><a href="TensorFlow.Gradient.html#calculateInputGrads"><span class="hs-identifier hs-var">calculateInputGrads</span></a></span><span> </span><span class="annot"><span class="annottext">Context NodeDef EdgeLabel
</span><a href="#local-6989586621679156834"><span class="hs-identifier hs-var">ctx</span></a></span><span> </span><span class="annot"><span class="annottext">Gradients a
</span><a href="#local-6989586621679156839"><span class="hs-identifier hs-var">outputGrads</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679156850"><span class="hs-identifier hs-var">gr</span></a></span><span>
</span><span id="line-287"></span><span>                  </span><span class="hs-comment">-- Calculate the gradients for each of the node's inputs.</span><span>
</span><span id="line-288"></span><span>                  </span><span class="annot"><span class="annottext">GradientsState a -&gt; BuildT Identity (GradientsState a)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span> </span><span class="annot"><span class="annottext">(GradientsState a -&gt; BuildT Identity (GradientsState a))
-&gt; GradientsState a -&gt; BuildT Identity (GradientsState a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Context NodeDef EdgeLabel
-&gt; [Maybe (Tensor Value a)] -&gt; GradientsState a -&gt; GradientsState a
forall a.
(TensorType a, Num a) =&gt;
Context NodeDef EdgeLabel
-&gt; [Maybe (Tensor Value a)] -&gt; GradientsState a -&gt; GradientsState a
</span><a href="TensorFlow.Gradient.html#updatePendingGradients"><span class="hs-identifier hs-var">updatePendingGradients</span></a></span><span> </span><span class="annot"><span class="annottext">Context NodeDef EdgeLabel
</span><a href="#local-6989586621679156834"><span class="hs-identifier hs-var">ctx</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe (Tensor Value a)]
</span><a href="#local-6989586621679156832"><span class="hs-identifier hs-var">inputGrads</span></a></span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156837"><span class="hs-identifier hs-var">nextState</span></a></span><span>
</span><span id="line-289"></span><span>                </span><span class="hs-keyword">else</span><span>
</span><span id="line-290"></span><span>                  </span><span class="annot"><span class="annottext">GradientsState a -&gt; BuildT Identity (GradientsState a)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156837"><span class="hs-identifier hs-var">nextState</span></a></span><span>
</span><span id="line-291"></span><span>
</span><span id="line-292"></span><span class="hs-comment">-- | Reduce accumulated gradients for each output to one Tensor.</span><span>
</span><span id="line-293"></span><span id="local-6989586621679157305"><span class="annot"><a href="TensorFlow.Gradient.html#sumPendingGradient"><span class="hs-identifier hs-type">sumPendingGradient</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientCompatible"><span class="hs-identifier hs-type">GradientCompatible</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157305"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-294"></span><span>                   </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#PendingGradients"><span class="hs-identifier hs-type">PendingGradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157305"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#Gradients"><span class="hs-identifier hs-type">Gradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157305"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-295"></span><span id="sumPendingGradient"><span class="annot"><span class="annottext">sumPendingGradient :: PendingGradients a -&gt; Build (Gradients a)
</span><a href="TensorFlow.Gradient.html#sumPendingGradient"><span class="hs-identifier hs-var hs-var">sumPendingGradient</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IntMap (BuildT Identity (Tensor Value a)) -&gt; Build (Gradients a)
forall (t :: * -&gt; *) (m :: * -&gt; *) a.
(Traversable t, Monad m) =&gt;
t (m a) -&gt; m (t a)
</span><span class="hs-identifier hs-var">sequence</span></span><span> </span><span class="annot"><span class="annottext">(IntMap (BuildT Identity (Tensor Value a)) -&gt; Build (Gradients a))
-&gt; (PendingGradients a
    -&gt; IntMap (BuildT Identity (Tensor Value a)))
-&gt; PendingGradients a
-&gt; Build (Gradients a)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">([Tensor Value a] -&gt; Maybe (BuildT Identity (Tensor Value a)))
-&gt; PendingGradients a -&gt; IntMap (BuildT Identity (Tensor Value a))
forall a b. (a -&gt; Maybe b) -&gt; IntMap a -&gt; IntMap b
</span><span class="hs-identifier hs-var">IntMap.mapMaybe</span></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a] -&gt; Maybe (BuildT Identity (Tensor Value a))
forall a (f :: * -&gt; *).
(a /= ByteString, a /= Bool, MonadBuild f, TensorType a) =&gt;
[Tensor Value a] -&gt; Maybe (f (Tensor Value a))
</span><a href="#local-6989586621679156827"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-296"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-297"></span><span>    </span><span id="local-6989586621679156827"><span class="annot"><span class="annottext">f :: [Tensor Value a] -&gt; Maybe (f (Tensor Value a))
</span><a href="#local-6989586621679156827"><span class="hs-identifier hs-var hs-var">f</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (f (Tensor Value a))
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-298"></span><span>    </span><span class="annot"><a href="#local-6989586621679156827"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156826"><span class="annot"><span class="annottext">x :: Tensor Value a
</span><a href="#local-6989586621679156826"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">f (Tensor Value a) -&gt; Maybe (f (Tensor Value a))
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; f (Tensor Value a)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156826"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-299"></span><span>    </span><span class="annot"><a href="#local-6989586621679156827"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span id="local-6989586621679156825"><span class="annot"><span class="annottext">xs :: [Tensor Value a]
</span><a href="#local-6989586621679156825"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">f (Tensor Value a) -&gt; Maybe (f (Tensor Value a))
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; f (Tensor Value a)
forall (m :: * -&gt; *) a.
MonadBuild m =&gt;
Tensor Build a -&gt; m (Tensor Value a)
</span><span class="hs-identifier hs-var">render</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; f (Tensor Value a))
-&gt; Tensor Build a -&gt; f (Tensor Value a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a] -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word32, Word64, Word8, Double, Float, Variant]
  t =&gt;
[Tensor v'1 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">addN</span></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156825"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-300"></span><span>
</span><span id="line-301"></span><span>
</span><span id="line-302"></span><span class="hs-comment">-- | Calculate the gradients of a node's input tensors.</span><span>
</span><span id="line-303"></span><span class="hs-comment">--</span><span>
</span><span id="line-304"></span><span class="hs-comment">-- This is mostly just a wrapper around opGrad.</span><span>
</span><span id="line-305"></span><span class="annot"><a href="TensorFlow.Gradient.html#calculateInputGrads"><span class="hs-identifier hs-type">calculateInputGrads</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679157289"><span class="annot"><a href="#local-6989586621679157289"><span class="hs-identifier hs-type">a</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientCompatible"><span class="hs-identifier hs-type">GradientCompatible</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157289"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-306"></span><span>                    </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Context</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#EdgeLabel"><span class="hs-identifier hs-type">EdgeLabel</span></a></span><span>
</span><span id="line-307"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#Gradients"><span class="hs-identifier hs-type">Gradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157289"><span class="hs-identifier hs-type">a</span></a></span><span>  </span><span class="hs-comment">-- ^ Output gradients of the node.</span><span>
</span><span id="line-308"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span>
</span><span id="line-309"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Value</span></span><span> </span><span class="annot"><a href="#local-6989586621679157289"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-310"></span><span id="calculateInputGrads"><span class="annot"><span class="annottext">calculateInputGrads :: Context NodeDef EdgeLabel
-&gt; Gradients a -&gt; Graph -&gt; Build [Maybe (Tensor Value a)]
</span><a href="TensorFlow.Gradient.html#calculateInputGrads"><span class="hs-identifier hs-var hs-var">calculateInputGrads</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156824"><span class="annot"><span class="annottext">inputEdges :: Adj EdgeLabel
</span><a href="#local-6989586621679156824"><span class="hs-identifier hs-var">inputEdges</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156823"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156823"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">)</span><span> </span><span id="local-6989586621679156822"><span class="annot"><span class="annottext">outputGrads :: Gradients a
</span><a href="#local-6989586621679156822"><span class="hs-identifier hs-var">outputGrads</span></a></span></span><span> </span><span id="local-6989586621679156821"><span class="annot"><span class="annottext">gr :: Graph
</span><a href="#local-6989586621679156821"><span class="hs-identifier hs-var">gr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-311"></span><span>    </span><span id="local-6989586621679156820"><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156820"><span class="hs-identifier hs-var">fullOutGrads</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; NodeName -&gt; Gradients a -&gt; Build [Tensor Value a]
forall a.
(TensorType a, Num a) =&gt;
OutputIx -&gt; NodeName -&gt; Gradients a -&gt; Build [Tensor Value a]
</span><a href="TensorFlow.Gradient.html#fullOutputGrads"><span class="hs-identifier hs-var">fullOutputGrads</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef -&gt; OutputIx
</span><a href="TensorFlow.Gradient.html#numOutputs"><span class="hs-identifier hs-var">numOutputs</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156823"><span class="hs-identifier hs-var">nodeDef</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef -&gt; NodeName
</span><a href="TensorFlow.Gradient.html#nodeDefName"><span class="hs-identifier hs-var">nodeDefName</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156823"><span class="hs-identifier hs-var">nodeDef</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-312"></span><span>                        </span><span class="annot"><span class="annottext">Gradients a
</span><a href="#local-6989586621679156822"><span class="hs-identifier hs-var">outputGrads</span></a></span><span>
</span><span id="line-313"></span><span>    </span><span class="annot"><span class="annottext">(Maybe (Tensor Build a)
 -&gt; BuildT Identity (Maybe (Tensor Value a)))
-&gt; [Maybe (Tensor Build a)] -&gt; Build [Maybe (Tensor Value a)]
forall (t :: * -&gt; *) (f :: * -&gt; *) a b.
(Traversable t, Applicative f) =&gt;
(a -&gt; f b) -&gt; t a -&gt; f (t b)
</span><span class="hs-identifier hs-var">traverse</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Tensor Build a -&gt; BuildT Identity (Tensor Value a))
-&gt; Maybe (Tensor Build a)
-&gt; BuildT Identity (Maybe (Tensor Value a))
forall (t :: * -&gt; *) (f :: * -&gt; *) a b.
(Traversable t, Applicative f) =&gt;
(a -&gt; f b) -&gt; t a -&gt; f (t b)
</span><span class="hs-identifier hs-var">traverse</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; BuildT Identity (Tensor Value a)
forall (m :: * -&gt; *) a.
MonadBuild m =&gt;
Tensor Build a -&gt; m (Tensor Value a)
</span><span class="hs-identifier hs-var">render</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([Maybe (Tensor Build a)] -&gt; Build [Maybe (Tensor Value a)])
-&gt; [Maybe (Tensor Build a)] -&gt; Build [Maybe (Tensor Value a)]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; GradientFunc a
forall a. GradientCompatible a =&gt; Text -&gt; GradientFunc a
</span><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156823"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike Text NodeDef NodeDef Text Text -&gt; Text
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;op&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">op</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156823"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156814"><span class="hs-identifier hs-var">inputTensors</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156820"><span class="hs-identifier hs-var">fullOutGrads</span></a></span><span>
</span><span id="line-314"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-315"></span><span>    </span><span class="hs-comment">-- Create a tensor from an edge (technically an Output, but it seems less</span><span>
</span><span id="line-316"></span><span>    </span><span class="hs-comment">-- confusing to refer to it as a tensor here).</span><span>
</span><span id="line-317"></span><span>    </span><span class="annot"><a href="#local-6989586621679156813"><span class="hs-identifier hs-type">edgeToTensor</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#EdgeLabel"><span class="hs-identifier hs-type">EdgeLabel</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Output</span></span><span>
</span><span id="line-318"></span><span>    </span><span id="local-6989586621679156813"><span class="annot"><span class="annottext">edgeToTensor :: (EdgeLabel, Node) -&gt; Output
</span><a href="#local-6989586621679156813"><span class="hs-identifier hs-var hs-var">edgeToTensor</span></a></span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621679156812"><span class="annot"><span class="annottext">i :: OutputIx
</span><a href="#local-6989586621679156812"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156811"><span class="annot"><span class="annottext">n :: Node
</span><a href="#local-6989586621679156811"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-319"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; Node -&gt; Maybe NodeDef
forall (gr :: * -&gt; * -&gt; *) a b.
Graph gr =&gt;
gr a b -&gt; Node -&gt; Maybe a
</span><span class="hs-identifier hs-var">FGL.lab</span></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679156821"><span class="hs-identifier hs-var">gr</span></a></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156811"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-320"></span><span>            </span><span class="annot"><span class="hs-identifier hs-type">Just</span></span><span> </span><span id="local-6989586621679156809"><span class="annot"><span class="annottext">edgeNodeDef :: NodeDef
</span><a href="#local-6989586621679156809"><span class="hs-identifier hs-var">edgeNodeDef</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; NodeName -&gt; Output
</span><span class="hs-identifier hs-var">Output</span></span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156812"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; NodeName
</span><span class="hs-identifier hs-var">NodeName</span></span><span> </span><span class="annot"><span class="annottext">(Text -&gt; NodeName) -&gt; Text -&gt; NodeName
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156809"><span class="hs-identifier hs-var">edgeNodeDef</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike Text NodeDef NodeDef Text Text -&gt; Text
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;name&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">name</span></span><span class="hs-special">)</span><span>
</span><span id="line-321"></span><span>            </span><span class="annot"><span class="hs-identifier hs-type">Nothing</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; Output
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="annot"><span class="annottext">([Char] -&gt; Output) -&gt; [Char] -&gt; Output
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="hs-string">&quot;calculateInputGrads: missing input node for &quot;</span></span><span>
</span><span id="line-322"></span><span>                               </span><span class="annot"><span class="annottext">[Char] -&gt; [Char] -&gt; [Char]
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; [Char]
</span><span class="hs-identifier hs-var">Text.unpack</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156823"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike Text NodeDef NodeDef Text Text -&gt; Text
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;name&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">name</span></span><span class="hs-special">)</span><span>
</span><span id="line-323"></span><span>    </span><span class="hs-comment">-- Input tensors, sorted by input index.</span><span>
</span><span id="line-324"></span><span>    </span><span id="local-6989586621679156814"><span class="annot"><span class="annottext">inputTensors :: [Output]
</span><a href="#local-6989586621679156814"><span class="hs-identifier hs-var hs-var">inputTensors</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((EdgeLabel, Node) -&gt; Output) -&gt; Adj EdgeLabel -&gt; [Output]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="annot"><span class="annottext">(EdgeLabel, Node) -&gt; Output
</span><a href="#local-6989586621679156813"><span class="hs-identifier hs-var">edgeToTensor</span></a></span><span> </span><span class="annot"><span class="annottext">(Adj EdgeLabel -&gt; [Output]) -&gt; Adj EdgeLabel -&gt; [Output]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">((EdgeLabel, Node) -&gt; (EdgeLabel, Node) -&gt; Ordering)
-&gt; Adj EdgeLabel -&gt; Adj EdgeLabel
forall a. (a -&gt; a -&gt; Ordering) -&gt; [a] -&gt; [a]
</span><span class="hs-identifier hs-var">sortBy</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((EdgeLabel, Node) -&gt; OutputIx)
-&gt; (EdgeLabel, Node) -&gt; (EdgeLabel, Node) -&gt; Ordering
forall a b. Ord a =&gt; (b -&gt; a) -&gt; b -&gt; b -&gt; Ordering
</span><span class="hs-identifier hs-var">comparing</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EdgeLabel -&gt; OutputIx
forall a b. (a, b) -&gt; b
</span><span class="hs-identifier hs-var">snd</span></span><span> </span><span class="annot"><span class="annottext">(EdgeLabel -&gt; OutputIx)
-&gt; ((EdgeLabel, Node) -&gt; EdgeLabel)
-&gt; (EdgeLabel, Node)
-&gt; OutputIx
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">(EdgeLabel, Node) -&gt; EdgeLabel
forall a b. (a, b) -&gt; a
</span><span class="hs-identifier hs-var">fst</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Adj EdgeLabel
</span><a href="#local-6989586621679156824"><span class="hs-identifier hs-var">inputEdges</span></a></span><span>
</span><span id="line-325"></span><span>
</span><span id="line-326"></span><span class="hs-comment">-- | Convert a Map of gradients to a list, with zeros for missing outputs.</span><span>
</span><span id="line-327"></span><span id="local-6989586621679157271"><span class="annot"><a href="TensorFlow.Gradient.html#fullOutputGrads"><span class="hs-identifier hs-type">fullOutputGrads</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">TensorType</span></span><span> </span><span class="annot"><a href="#local-6989586621679157271"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Num</span></span><span> </span><span class="annot"><a href="#local-6989586621679157271"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-328"></span><span>                </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span>  </span><span class="hs-comment">-- ^ Number of outputs.</span><span>
</span><span id="line-329"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span>
</span><span id="line-330"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#Gradients"><span class="hs-identifier hs-type">Gradients</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157271"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-331"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Value</span></span><span> </span><span class="annot"><a href="#local-6989586621679157271"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-332"></span><span id="fullOutputGrads"><span class="annot"><span class="annottext">fullOutputGrads :: OutputIx -&gt; NodeName -&gt; Gradients a -&gt; Build [Tensor Value a]
</span><a href="TensorFlow.Gradient.html#fullOutputGrads"><span class="hs-identifier hs-var hs-var">fullOutputGrads</span></a></span></span><span> </span><span id="local-6989586621679156806"><span class="annot"><span class="annottext">n :: OutputIx
</span><a href="#local-6989586621679156806"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679156805"><span class="annot"><span class="annottext">o :: NodeName
</span><a href="#local-6989586621679156805"><span class="hs-identifier hs-var">o</span></a></span></span><span> </span><span id="local-6989586621679156804"><span class="annot"><span class="annottext">gs :: Gradients a
</span><a href="#local-6989586621679156804"><span class="hs-identifier hs-var">gs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-333"></span><span>    </span><span class="annot"><span class="annottext">(OutputIx -&gt; BuildT Identity (Tensor Value a))
-&gt; [OutputIx] -&gt; Build [Tensor Value a]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><span class="hs-identifier hs-var">mapM</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679156802"><span class="annot"><span class="annottext">i :: OutputIx
</span><a href="#local-6989586621679156802"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">BuildT Identity (Tensor Value a)
-&gt; (Tensor Value a -&gt; BuildT Identity (Tensor Value a))
-&gt; Maybe (Tensor Value a)
-&gt; BuildT Identity (Tensor Value a)
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><span class="hs-identifier hs-var">maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; BuildT Identity (Tensor Value a)
forall (m :: * -&gt; *) a.
MonadBuild m =&gt;
Tensor Build a -&gt; m (Tensor Value a)
</span><span class="hs-identifier hs-var">render</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; BuildT Identity (Tensor Value a))
-&gt; Tensor Build a -&gt; BuildT Identity (Tensor Value a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; Tensor Build a
</span><a href="#local-6989586621679156801"><span class="hs-identifier hs-var">zero</span></a></span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156802"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; BuildT Identity (Tensor Value a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><span class="hs-identifier hs-var">return</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Gradients a
</span><a href="#local-6989586621679156804"><span class="hs-identifier hs-var">gs</span></a></span><span> </span><span class="annot"><span class="annottext">Gradients a
-&gt; FoldLike
     (Maybe (Tensor Value a))
     (Gradients a)
     (Gradients a)
     (Maybe (Tensor Value a))
     (Maybe (Tensor Value a))
-&gt; Maybe (Tensor Value a)
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; Lens' (Gradients a) (Maybe (Tensor Value a))
forall v. OutputIx -&gt; Lens' (IntMap v) (Maybe v)
</span><a href="TensorFlow.Gradient.html#outputIxAt"><span class="hs-identifier hs-var">outputIxAt</span></a></span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156802"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">0</span></span><span class="hs-glyph">..</span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156806"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">OutputIx -&gt; OutputIx -&gt; OutputIx
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-glyph hs-var">-</span></span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">]</span><span>
</span><span id="line-334"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-335"></span><span>    </span><span class="hs-comment">-- A tensor of zeros with the same shape as the i'th output.</span><span>
</span><span id="line-336"></span><span>    </span><span id="local-6989586621679156801"><span class="annot"><span class="annottext">zero :: OutputIx -&gt; Tensor Build a
</span><a href="#local-6989586621679156801"><span class="hs-identifier hs-var hs-var">zero</span></a></span></span><span> </span><span id="local-6989586621679156800"><span class="annot"><span class="annottext">i :: OutputIx
</span><a href="#local-6989586621679156800"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">zerosLike</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Tensor Build a)
-&gt; Tensor Build a -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OutputIx -&gt; NodeName -&gt; Output
</span><span class="hs-identifier hs-var">Output</span></span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156800"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156805"><span class="hs-identifier hs-var">o</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-337"></span><span>
</span><span id="line-338"></span><span>
</span><span id="line-339"></span><span class="hs-comment">-- | Update the pending gradients of a node's inputs.</span><span>
</span><span id="line-340"></span><span class="annot"><a href="TensorFlow.Gradient.html#updatePendingGradients"><span class="hs-identifier hs-type">updatePendingGradients</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679157288"><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">TensorType</span></span><span> </span><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Num</span></span><span> </span><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-341"></span><span>                       </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Context</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#EdgeLabel"><span class="hs-identifier hs-type">EdgeLabel</span></a></span><span>
</span><span id="line-342"></span><span>                       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Value</span></span><span> </span><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-343"></span><span>                       </span><span class="hs-comment">-- ^ Gradient of each input tensor.</span><span>
</span><span id="line-344"></span><span>                       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-345"></span><span>                       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-346"></span><span id="updatePendingGradients"><span class="annot"><span class="annottext">updatePendingGradients :: Context NodeDef EdgeLabel
-&gt; [Maybe (Tensor Value a)] -&gt; GradientsState a -&gt; GradientsState a
</span><a href="TensorFlow.Gradient.html#updatePendingGradients"><span class="hs-identifier hs-var hs-var">updatePendingGradients</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156798"><span class="annot"><span class="annottext">inputEdges :: Adj EdgeLabel
</span><a href="#local-6989586621679156798"><span class="hs-identifier hs-var">inputEdges</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156797"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156797"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">)</span><span> </span><span id="local-6989586621679156796"><span class="annot"><span class="annottext">inputGrads :: [Maybe (Tensor Value a)]
</span><a href="#local-6989586621679156796"><span class="hs-identifier hs-var">inputGrads</span></a></span></span><span> </span><span id="local-6989586621679156795"><span class="annot"><span class="annottext">initState :: GradientsState a
</span><a href="#local-6989586621679156795"><span class="hs-identifier hs-var">initState</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-347"></span><span>    </span><span class="annot"><span class="annottext">(GradientsState a -&gt; (EdgeLabel, Node) -&gt; GradientsState a)
-&gt; GradientsState a -&gt; Adj EdgeLabel -&gt; GradientsState a
forall (t :: * -&gt; *) b a.
Foldable t =&gt;
(b -&gt; a -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><span class="hs-identifier hs-var">foldl'</span></span><span> </span><span class="annot"><span class="annottext">GradientsState a -&gt; (EdgeLabel, Node) -&gt; GradientsState a
</span><a href="#local-6989586621679156794"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156795"><span class="hs-identifier hs-var">initState</span></a></span><span> </span><span class="annot"><span class="annottext">Adj EdgeLabel
</span><a href="#local-6989586621679156798"><span class="hs-identifier hs-var">inputEdges</span></a></span><span>
</span><span id="line-348"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-349"></span><span>    </span><span class="annot"><a href="#local-6989586621679156794"><span class="hs-identifier hs-type">go</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#EdgeLabel"><span class="hs-identifier hs-type">EdgeLabel</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientsState"><span class="hs-identifier hs-type">GradientsState</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157288"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-350"></span><span>    </span><span id="local-6989586621679156794"><span class="annot"><span class="annottext">go :: GradientsState a -&gt; (EdgeLabel, Node) -&gt; GradientsState a
</span><a href="#local-6989586621679156794"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679156793"><span class="annot"><span class="annottext">state :: GradientsState a
</span><a href="#local-6989586621679156793"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621679156792"><span class="annot"><span class="annottext">outIndex :: OutputIx
</span><a href="#local-6989586621679156792"><span class="hs-identifier hs-var">outIndex</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span> </span><span id="local-6989586621679156790"><span class="annot"><span class="annottext">inIndex :: Node
</span><a href="#local-6989586621679156790"><span class="hs-identifier hs-var">inIndex</span></a></span></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156789"><span class="annot"><span class="annottext">node :: Node
</span><a href="#local-6989586621679156789"><span class="hs-identifier hs-var">node</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-351"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Value a)
</span><a href="#local-6989586621679156788"><span class="hs-identifier hs-var">maybeGradient</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-352"></span><span>            </span><span class="annot"><span class="hs-identifier hs-type">Nothing</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156793"><span class="hs-identifier hs-var">state</span></a></span><span>
</span><span id="line-353"></span><span>            </span><span class="annot"><span class="hs-identifier hs-type">Just</span></span><span> </span><span id="local-6989586621679156787"><span class="annot"><span class="annottext">g :: Tensor Value a
</span><a href="#local-6989586621679156787"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-354"></span><span>                </span><span class="hs-comment">-- Add to the list of pending gradients for this tensor.</span><span>
</span><span id="line-355"></span><span>                </span><span class="annot"><span class="annottext">GradientsState a
</span><a href="#local-6989586621679156793"><span class="hs-identifier hs-var">state</span></a></span><span> </span><span class="annot"><span class="annottext">GradientsState a
-&gt; (GradientsState a -&gt; GradientsState a) -&gt; GradientsState a
forall s t. s -&gt; (s -&gt; t) -&gt; t
</span><span class="hs-operator hs-var">&amp;</span></span><span> </span><span class="annot"><span class="annottext">LensLike' f (GradientsState a) (Map Node (PendingGradients a))
forall a. Lens' (GradientsState a) (Map Node (PendingGradients a))
</span><a href="TensorFlow.Gradient.html#gradientsPending"><span class="hs-identifier hs-var">gradientsPending</span></a></span><span>
</span><span id="line-356"></span><span>                      </span><span class="annot"><span class="annottext">LensLike' f (GradientsState a) (Map Node (PendingGradients a))
-&gt; (([Tensor Value a] -&gt; f [Tensor Value a])
    -&gt; Map Node (PendingGradients a)
    -&gt; f (Map Node (PendingGradients a)))
-&gt; ([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; GradientsState a
-&gt; f (GradientsState a)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Node
-&gt; Lens'
     (Map Node (PendingGradients a)) (Maybe (PendingGradients a))
forall k v. Ord k =&gt; k -&gt; Lens' (Map k v) (Maybe v)
</span><span class="hs-identifier hs-var">at</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156789"><span class="hs-identifier hs-var">node</span></a></span><span>
</span><span id="line-357"></span><span>                      </span><span class="annot"><span class="annottext">LensLike'
  f (Map Node (PendingGradients a)) (Maybe (PendingGradients a))
-&gt; (([Tensor Value a] -&gt; f [Tensor Value a])
    -&gt; Maybe (PendingGradients a) -&gt; f (Maybe (PendingGradients a)))
-&gt; ([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; Map Node (PendingGradients a)
-&gt; f (Map Node (PendingGradients a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">LensLike' f (Maybe (PendingGradients a)) (PendingGradients a)
forall (t :: * -&gt; *) v.
(Monoid (t v), Foldable t) =&gt;
Lens' (Maybe (t v)) (t v)
</span><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-var">nonEmpty</span></a></span><span>
</span><span id="line-358"></span><span>                      </span><span class="annot"><span class="annottext">LensLike' f (Maybe (PendingGradients a)) (PendingGradients a)
-&gt; (([Tensor Value a] -&gt; f [Tensor Value a])
    -&gt; PendingGradients a -&gt; f (PendingGradients a))
-&gt; ([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; Maybe (PendingGradients a)
-&gt; f (Maybe (PendingGradients a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; Lens' (PendingGradients a) (Maybe [Tensor Value a])
forall v. OutputIx -&gt; Lens' (IntMap v) (Maybe v)
</span><a href="TensorFlow.Gradient.html#outputIxAt"><span class="hs-identifier hs-var">outputIxAt</span></a></span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156792"><span class="hs-identifier hs-var">outIndex</span></a></span><span>
</span><span id="line-359"></span><span>                      </span><span class="annot"><span class="annottext">LensLike' f (PendingGradients a) (Maybe [Tensor Value a])
-&gt; (([Tensor Value a] -&gt; f [Tensor Value a])
    -&gt; Maybe [Tensor Value a] -&gt; f (Maybe [Tensor Value a]))
-&gt; ([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; PendingGradients a
-&gt; f (PendingGradients a)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">([Tensor Value a] -&gt; f [Tensor Value a])
-&gt; Maybe [Tensor Value a] -&gt; f (Maybe [Tensor Value a])
forall (t :: * -&gt; *) v.
(Monoid (t v), Foldable t) =&gt;
Lens' (Maybe (t v)) (t v)
</span><a href="TensorFlow.Gradient.html#nonEmpty"><span class="hs-identifier hs-var">nonEmpty</span></a></span><span>
</span><span id="line-360"></span><span>                      </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *).
 Identical f =&gt;
 ([Tensor Value a] -&gt; f [Tensor Value a])
 -&gt; GradientsState a -&gt; f (GradientsState a))
-&gt; ([Tensor Value a] -&gt; [Tensor Value a])
-&gt; GradientsState a
-&gt; GradientsState a
forall s t a b. Setter s t a b -&gt; (a -&gt; b) -&gt; s -&gt; t
</span><span class="hs-operator hs-var">%~</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156787"><span class="hs-identifier hs-var">g</span></a></span><span class="annot"><span class="annottext">Tensor Value a -&gt; [Tensor Value a] -&gt; [Tensor Value a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="hs-special">)</span><span>
</span><span id="line-361"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-362"></span><span>        </span><span id="local-6989586621679156786"><span class="annot"><span class="annottext">badSizeErr :: Maybe (Tensor Value a)
</span><a href="#local-6989586621679156786"><span class="hs-identifier hs-var hs-var">badSizeErr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; Maybe (Tensor Value a)
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="annot"><span class="annottext">([Char] -&gt; Maybe (Tensor Value a))
-&gt; [Char] -&gt; Maybe (Tensor Value a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; Node -&gt; Node -&gt; [Char] -&gt; [Char]
forall r. PrintfType r =&gt; [Char] -&gt; r
</span><span class="hs-identifier hs-var">printf</span></span><span> </span><span class="annot"><span class="hs-string">&quot;updatePendingGradients: bad input index \
                                    \%d for inputGrads of length %d in %s&quot;</span></span><span>
</span><span id="line-364"></span><span>                                    </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156790"><span class="hs-identifier hs-var">inIndex</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Maybe (Tensor Value a)] -&gt; Node
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Node
</span><span class="hs-identifier hs-var">length</span></span><span> </span><span class="annot"><span class="annottext">[Maybe (Tensor Value a)]
</span><a href="#local-6989586621679156796"><span class="hs-identifier hs-var">inputGrads</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-365"></span><span>                                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; [Char]
forall a. Show a =&gt; a -&gt; [Char]
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156797"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike Text NodeDef NodeDef Text Text -&gt; Text
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;name&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">name</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-366"></span><span>        </span><span id="local-6989586621679156788"><span class="annot"><span class="annottext">maybeGradient :: Maybe (Tensor Value a)
</span><a href="#local-6989586621679156788"><span class="hs-identifier hs-var hs-var">maybeGradient</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Value a)
-&gt; Maybe (Maybe (Tensor Value a)) -&gt; Maybe (Tensor Value a)
forall a. a -&gt; Maybe a -&gt; a
</span><span class="hs-identifier hs-var">fromMaybe</span></span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Value a)
</span><a href="#local-6989586621679156786"><span class="hs-identifier hs-var">badSizeErr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Maybe (Tensor Value a)] -&gt; Node -&gt; Maybe (Maybe (Tensor Value a))
forall a. [a] -&gt; Node -&gt; Maybe a
</span><a href="TensorFlow.Gradient.html#safeIndex"><span class="hs-identifier hs-var">safeIndex</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe (Tensor Value a)]
</span><a href="#local-6989586621679156796"><span class="hs-identifier hs-var">inputGrads</span></a></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156790"><span class="hs-identifier hs-var">inIndex</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-367"></span><span>
</span><span id="line-368"></span><span>
</span><span id="line-369"></span><span class="hs-comment">-- | Create a graph that includes a node and its transitive dependencies.</span><span>
</span><span id="line-370"></span><span class="annot"><a href="TensorFlow.Gradient.html#createGraph"><span class="hs-identifier hs-type">createGraph</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span class="hs-special">)</span><span>
</span><span id="line-371"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Gradient.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">FGL.Node</span></span><span class="hs-special">)</span><span>
</span><span id="line-372"></span><span id="createGraph"><span class="annot"><span class="annottext">createGraph :: NodeName -&gt; (NodeName -&gt; NodeDef) -&gt; (Graph, Map NodeName Node)
</span><a href="TensorFlow.Gradient.html#createGraph"><span class="hs-identifier hs-var hs-var">createGraph</span></a></span></span><span> </span><span id="local-6989586621679156784"><span class="annot"><span class="annottext">nodeName :: NodeName
</span><a href="#local-6989586621679156784"><span class="hs-identifier hs-var">nodeName</span></a></span></span><span> </span><span id="local-6989586621679156783"><span class="annot"><span class="annottext">nodeDefLookup :: NodeName -&gt; NodeDef
</span><a href="#local-6989586621679156783"><span class="hs-identifier hs-var">nodeDefLookup</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(NodeName -&gt; NodeDef) -&gt; Gr NodeName EdgeLabel -&gt; Graph
forall (gr :: * -&gt; * -&gt; *) a c b.
DynGraph gr =&gt;
(a -&gt; c) -&gt; gr a b -&gt; gr c b
</span><span class="hs-identifier hs-var">FGL.nmap</span></span><span> </span><span class="annot"><span class="annottext">NodeName -&gt; NodeDef
</span><a href="#local-6989586621679156783"><span class="hs-identifier hs-var">nodeDefLookup</span></a></span><span> </span><span class="annot"><span class="annottext">Gr NodeName EdgeLabel
</span><a href="#local-6989586621679156781"><span class="hs-identifier hs-var">graph</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Map NodeName Node
</span><a href="#local-6989586621679156780"><span class="hs-identifier hs-var">nodeMap</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-373"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-374"></span><span>    </span><span class="hs-comment">-- Parse a tensor name.</span><span>
</span><span id="line-375"></span><span>    </span><span class="annot"><a href="#local-6989586621679156779"><span class="hs-identifier hs-type">parseTensorName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Text</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span class="hs-special">)</span><span>
</span><span id="line-376"></span><span>    </span><span id="local-6989586621679156779"><span class="annot"><span class="annottext">parseTensorName :: Text -&gt; Maybe (NodeName, OutputIx)
</span><a href="#local-6989586621679156779"><span class="hs-identifier hs-var hs-var">parseTensorName</span></a></span></span><span> </span><span id="local-6989586621679156778"><span class="annot"><span class="annottext">n :: Text
</span><a href="#local-6989586621679156778"><span class="hs-identifier hs-var">n</span></a></span></span><span>
</span><span id="line-377"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Text -&gt; Bool
</span><span class="hs-identifier hs-var">Text.null</span></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156778"><span class="hs-identifier hs-var">n</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; Maybe (NodeName, OutputIx)
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="annot"><span class="hs-string">&quot;parseTensorName: empty name&quot;</span></span><span>
</span><span id="line-378"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Text -&gt; Char
</span><span class="hs-identifier hs-var">Text.head</span></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156778"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="hs-char">'^'</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (NodeName, OutputIx)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>  </span><span class="hs-comment">-- Control edge</span><span>
</span><span id="line-379"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">otherwise</span></span><span>          </span><span class="hs-glyph">=</span><span>
</span><span id="line-380"></span><span>            </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156775"><span class="annot"><span class="annottext">nm :: Text
</span><a href="#local-6989586621679156775"><span class="hs-identifier hs-var">nm</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156774"><span class="annot"><span class="annottext">indexStr :: Text
</span><a href="#local-6989586621679156774"><span class="hs-identifier hs-var">indexStr</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Text -&gt; Text -&gt; (Text, Text)
</span><span class="hs-identifier hs-var">Text.breakOn</span></span><span> </span><span class="annot"><span class="hs-string">&quot;:&quot;</span></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156778"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-381"></span><span>                </span><span id="local-6989586621679156772"><span class="annot"><span class="annottext">index :: Node
</span><a href="#local-6989586621679156772"><span class="hs-identifier hs-var hs-var">index</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Text -&gt; Bool
</span><span class="hs-identifier hs-var">Text.null</span></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156774"><span class="hs-identifier hs-var">indexStr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-number">0</span></span><span>
</span><span id="line-382"></span><span>                      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">otherwise</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; Node
forall a. Read a =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">read</span></span><span> </span><span class="annot"><span class="annottext">([Char] -&gt; Node) -&gt; [Char] -&gt; Node
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; [Char]
</span><span class="hs-identifier hs-var">Text.unpack</span></span><span> </span><span class="annot"><span class="annottext">(Text -&gt; [Char]) -&gt; Text -&gt; [Char]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; Text
</span><span class="hs-identifier hs-var">Text.tail</span></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156774"><span class="hs-identifier hs-var">indexStr</span></a></span><span>
</span><span id="line-383"></span><span>            </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">(NodeName, OutputIx) -&gt; Maybe (NodeName, OutputIx)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; NodeName
</span><span class="hs-identifier hs-var">NodeName</span></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156775"><span class="hs-identifier hs-var">nm</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Node -&gt; OutputIx
</span><span class="hs-identifier hs-var">OutputIx</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156772"><span class="hs-identifier hs-var">index</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-384"></span><span>
</span><span id="line-385"></span><span>    </span><span class="hs-comment">-- Build a map from node name to outward edges.</span><span>
</span><span id="line-386"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-387"></span><span>    </span><span class="hs-comment">-- The state is the set of visited nodes.</span><span>
</span><span id="line-388"></span><span>    </span><span class="annot"><a href="#local-6989586621679156769"><span class="hs-identifier hs-type">collect</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span class="hs-special">)</span><span>
</span><span id="line-389"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span>
</span><span id="line-390"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">State</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Set</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span class="hs-special">)</span><span>
</span><span id="line-391"></span><span>                     </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Map</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-392"></span><span>    </span><span id="local-6989586621679156769"><span class="annot"><span class="annottext">collect :: Maybe (NodeName, OutputIx, OutputIx)
-&gt; NodeName
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
</span><a href="#local-6989586621679156769"><span class="hs-identifier hs-var hs-var">collect</span></a></span></span><span> </span><span id="local-6989586621679156768"><span class="annot"><span class="annottext">outgoingEdge :: Maybe (NodeName, OutputIx, OutputIx)
</span><a href="#local-6989586621679156768"><span class="hs-identifier hs-var">outgoingEdge</span></a></span></span><span> </span><span id="local-6989586621679156767"><span class="annot"><span class="annottext">nm :: NodeName
</span><a href="#local-6989586621679156767"><span class="hs-identifier hs-var">nm</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-393"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156766"><span class="annot"><span class="annottext">nextLookup :: Map NodeName [(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156766"><span class="hs-identifier hs-var hs-var">nextLookup</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeName
-&gt; [(NodeName, OutputIx, OutputIx)]
-&gt; Map NodeName [(NodeName, OutputIx, OutputIx)]
forall k a. k -&gt; a -&gt; Map k a
</span><span class="hs-identifier hs-var">Map.singleton</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156767"><span class="hs-identifier hs-var">nm</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe (NodeName, OutputIx, OutputIx)
-&gt; [(NodeName, OutputIx, OutputIx)]
forall a. Maybe a -&gt; [a]
</span><span class="hs-identifier hs-var">maybeToList</span></span><span> </span><span class="annot"><span class="annottext">Maybe (NodeName, OutputIx, OutputIx)
</span><a href="#local-6989586621679156768"><span class="hs-identifier hs-var">outgoingEdge</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-394"></span><span>        </span><span id="local-6989586621679156764"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156764"><span class="hs-identifier hs-var">seen</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Set NodeName -&gt; Bool) -&gt; StateT (Set NodeName) Identity Bool
forall s (m :: * -&gt; *) a. MonadState s m =&gt; (s -&gt; a) -&gt; m a
</span><span class="hs-identifier hs-var">gets</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeName -&gt; Set NodeName -&gt; Bool
forall a. Ord a =&gt; a -&gt; Set a -&gt; Bool
</span><span class="hs-identifier hs-var">Set.member</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156767"><span class="hs-identifier hs-var">nm</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-395"></span><span>        </span><span class="annot"><span class="annottext">(Set NodeName -&gt; Set NodeName) -&gt; StateT (Set NodeName) Identity ()
forall s (m :: * -&gt; *). MonadState s m =&gt; (s -&gt; s) -&gt; m ()
</span><span class="hs-identifier hs-var">modify</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeName -&gt; Set NodeName -&gt; Set NodeName
forall a. Ord a =&gt; a -&gt; Set a -&gt; Set a
</span><span class="hs-identifier hs-var">Set.insert</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156767"><span class="hs-identifier hs-var">nm</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-396"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156764"><span class="hs-identifier hs-var">seen</span></a></span><span>
</span><span id="line-397"></span><span>            </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span> </span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156766"><span class="hs-identifier hs-var">nextLookup</span></a></span><span>
</span><span id="line-398"></span><span>            </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-399"></span><span>                </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156761"><span class="annot"><span class="annottext">inputs :: [Text]
</span><a href="#local-6989586621679156761"><span class="hs-identifier hs-var hs-var">inputs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeName -&gt; NodeDef
</span><a href="#local-6989586621679156783"><span class="hs-identifier hs-var">nodeDefLookup</span></a></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156767"><span class="hs-identifier hs-var">nm</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike [Text] NodeDef NodeDef [Text] [Text] -&gt; [Text]
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike [Text] NodeDef NodeDef [Text] [Text]
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;input&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">input</span></span><span>
</span><span id="line-400"></span><span>                    </span><span id="local-6989586621679156760"><span class="annot"><span class="annottext">recurse :: OutputIx
-&gt; (NodeName, OutputIx)
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
</span><a href="#local-6989586621679156760"><span class="hs-identifier hs-var hs-var">recurse</span></a></span></span><span> </span><span id="local-6989586621679156759"><span class="annot"><span class="annottext">inIndex :: OutputIx
</span><a href="#local-6989586621679156759"><span class="hs-identifier hs-var">inIndex</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156758"><span class="annot"><span class="annottext">parentName :: NodeName
</span><a href="#local-6989586621679156758"><span class="hs-identifier hs-var">parentName</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156757"><span class="annot"><span class="annottext">outIndex :: OutputIx
</span><a href="#local-6989586621679156757"><span class="hs-identifier hs-var">outIndex</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-401"></span><span>                        </span><span class="annot"><span class="annottext">Maybe (NodeName, OutputIx, OutputIx)
-&gt; NodeName
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
</span><a href="#local-6989586621679156769"><span class="hs-identifier hs-var">collect</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(NodeName, OutputIx, OutputIx)
-&gt; Maybe (NodeName, OutputIx, OutputIx)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156767"><span class="hs-identifier hs-var">nm</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156757"><span class="hs-identifier hs-var">outIndex</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156759"><span class="hs-identifier hs-var">inIndex</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156758"><span class="hs-identifier hs-var">parentName</span></a></span><span>
</span><span id="line-402"></span><span>                </span><span id="local-6989586621679156756"><span class="annot"><span class="annottext">[Map NodeName [(NodeName, OutputIx, OutputIx)]]
</span><a href="#local-6989586621679156756"><span class="hs-identifier hs-var">subEdgeLookups</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-403"></span><span>                    </span><span class="annot"><span class="annottext">(OutputIx
 -&gt; (NodeName, OutputIx)
 -&gt; State
      (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)]))
-&gt; [OutputIx]
-&gt; [(NodeName, OutputIx)]
-&gt; StateT
     (Set NodeName)
     Identity
     [Map NodeName [(NodeName, OutputIx, OutputIx)]]
forall (m :: * -&gt; *) a b c.
Applicative m =&gt;
(a -&gt; b -&gt; m c) -&gt; [a] -&gt; [b] -&gt; m [c]
</span><span class="hs-identifier hs-var">zipWithM</span></span><span> </span><span class="annot"><span class="annottext">OutputIx
-&gt; (NodeName, OutputIx)
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
</span><a href="#local-6989586621679156760"><span class="hs-identifier hs-var">recurse</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">0</span></span><span class="hs-glyph">..</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">([(NodeName, OutputIx)]
 -&gt; StateT
      (Set NodeName)
      Identity
      [Map NodeName [(NodeName, OutputIx, OutputIx)]])
-&gt; [(NodeName, OutputIx)]
-&gt; StateT
     (Set NodeName)
     Identity
     [Map NodeName [(NodeName, OutputIx, OutputIx)]]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(Text -&gt; Maybe (NodeName, OutputIx))
-&gt; [Text] -&gt; [(NodeName, OutputIx)]
forall a b. (a -&gt; Maybe b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">mapMaybe</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; Maybe (NodeName, OutputIx)
</span><a href="#local-6989586621679156779"><span class="hs-identifier hs-var">parseTensorName</span></a></span><span> </span><span class="annot"><span class="annottext">[Text]
</span><a href="#local-6989586621679156761"><span class="hs-identifier hs-var">inputs</span></a></span><span>
</span><span id="line-404"></span><span>                </span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span> </span><span class="annot"><span class="annottext">(Map NodeName [(NodeName, OutputIx, OutputIx)]
 -&gt; State
      (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)]))
-&gt; Map NodeName [(NodeName, OutputIx, OutputIx)]
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">([(NodeName, OutputIx, OutputIx)]
 -&gt; [(NodeName, OutputIx, OutputIx)]
 -&gt; [(NodeName, OutputIx, OutputIx)])
-&gt; [Map NodeName [(NodeName, OutputIx, OutputIx)]]
-&gt; Map NodeName [(NodeName, OutputIx, OutputIx)]
forall (f :: * -&gt; *) k a.
(Foldable f, Ord k) =&gt;
(a -&gt; a -&gt; a) -&gt; f (Map k a) -&gt; Map k a
</span><span class="hs-identifier hs-var">Map.unionsWith</span></span><span> </span><span class="annot"><span class="annottext">[(NodeName, OutputIx, OutputIx)]
-&gt; [(NodeName, OutputIx, OutputIx)]
-&gt; [(NodeName, OutputIx, OutputIx)]
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">(++)</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156766"><span class="hs-identifier hs-var">nextLookup</span></a></span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
-&gt; [Map NodeName [(NodeName, OutputIx, OutputIx)]]
-&gt; [Map NodeName [(NodeName, OutputIx, OutputIx)]]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[Map NodeName [(NodeName, OutputIx, OutputIx)]]
</span><a href="#local-6989586621679156756"><span class="hs-identifier hs-var">subEdgeLookups</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-405"></span><span>
</span><span id="line-406"></span><span>    </span><span id="local-6989586621679156754"><span class="annot"><span class="annottext">edgeLookup :: Map NodeName [(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156754"><span class="hs-identifier hs-var hs-var">edgeLookup</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">State
  (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
-&gt; Set NodeName -&gt; Map NodeName [(NodeName, OutputIx, OutputIx)]
forall s a. State s a -&gt; s -&gt; a
</span><span class="hs-identifier hs-var">evalState</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe (NodeName, OutputIx, OutputIx)
-&gt; NodeName
-&gt; State
     (Set NodeName) (Map NodeName [(NodeName, OutputIx, OutputIx)])
</span><a href="#local-6989586621679156769"><span class="hs-identifier hs-var">collect</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (NodeName, OutputIx, OutputIx)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156784"><span class="hs-identifier hs-var">nodeName</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Set NodeName
forall a. Set a
</span><span class="hs-identifier hs-var">Set.empty</span></span><span>
</span><span id="line-407"></span><span>    </span><span class="hs-comment">-- Associate an ID with each node name.</span><span>
</span><span id="line-408"></span><span>    </span><span id="local-6989586621679156780"><span class="annot"><span class="annottext">nodeMap :: Map NodeName Node
</span><a href="#local-6989586621679156780"><span class="hs-identifier hs-var hs-var">nodeMap</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(NodeName, Node)] -&gt; Map NodeName Node
forall k a. Ord k =&gt; [(k, a)] -&gt; Map k a
</span><span class="hs-identifier hs-var">Map.fromList</span></span><span> </span><span class="annot"><span class="annottext">([(NodeName, Node)] -&gt; Map NodeName Node)
-&gt; [(NodeName, Node)] -&gt; Map NodeName Node
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[NodeName] -&gt; [Node] -&gt; [(NodeName, Node)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><span class="hs-identifier hs-var">zip</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)] -&gt; [NodeName]
forall k a. Map k a -&gt; [k]
</span><span class="hs-identifier hs-var">Map.keys</span></span><span> </span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156754"><span class="hs-identifier hs-var">edgeLookup</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">0</span></span><span class="hs-glyph">..</span><span class="hs-special">]</span><span>
</span><span id="line-409"></span><span>    </span><span class="hs-comment">-- Create the graph.</span><span>
</span><span id="line-410"></span><span>    </span><span id="local-6989586621679156781"><span class="annot"><span class="annottext">graph :: Gr NodeName EdgeLabel
</span><a href="#local-6989586621679156781"><span class="hs-identifier hs-var hs-var">graph</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[LNode NodeName] -&gt; [LEdge EdgeLabel] -&gt; Gr NodeName EdgeLabel
forall (gr :: * -&gt; * -&gt; *) a b.
Graph gr =&gt;
[LNode a] -&gt; [LEdge b] -&gt; gr a b
</span><span class="hs-identifier hs-var">FGL.mkGraph</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(NodeName, Node) -&gt; LNode NodeName
forall a b. (a, b) -&gt; (b, a)
</span><span class="hs-identifier hs-var">swap</span></span><span> </span><span class="annot"><span class="annottext">((NodeName, Node) -&gt; LNode NodeName)
-&gt; [(NodeName, Node)] -&gt; [LNode NodeName]
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">Map NodeName Node -&gt; [(NodeName, Node)]
forall k a. Map k a -&gt; [(k, a)]
</span><span class="hs-identifier hs-var">Map.toList</span></span><span> </span><span class="annot"><span class="annottext">Map NodeName Node
</span><a href="#local-6989586621679156780"><span class="hs-identifier hs-var">nodeMap</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-411"></span><span>                        </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map NodeName Node
</span><a href="#local-6989586621679156780"><span class="hs-identifier hs-var">nodeMap</span></a></span><span> </span><span class="annot"><span class="annottext">Map NodeName Node -&gt; NodeName -&gt; Node
forall k a. Ord k =&gt; Map k a -&gt; k -&gt; a
</span><span class="hs-operator hs-var">Map.!</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156748"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Map NodeName Node
</span><a href="#local-6989586621679156780"><span class="hs-identifier hs-var">nodeMap</span></a></span><span> </span><span class="annot"><span class="annottext">Map NodeName Node -&gt; NodeName -&gt; Node
forall k a. Ord k =&gt; Map k a -&gt; k -&gt; a
</span><span class="hs-operator hs-var">Map.!</span></span><span> </span><span class="annot"><span class="annottext">NodeName
</span><a href="#local-6989586621679156747"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156746"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">OutputIx
</span><a href="#local-6989586621679156745"><span class="hs-identifier hs-var">j</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-412"></span><span>                        </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156748"><span class="annot"><span class="annottext">n :: NodeName
</span><a href="#local-6989586621679156748"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156744"><span class="annot"><span class="annottext">edges :: [(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156744"><span class="hs-identifier hs-var">edges</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
-&gt; [(NodeName, [(NodeName, OutputIx, OutputIx)])]
forall k a. Map k a -&gt; [(k, a)]
</span><span class="hs-identifier hs-var">Map.toList</span></span><span> </span><span class="annot"><span class="annottext">Map NodeName [(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156754"><span class="hs-identifier hs-var">edgeLookup</span></a></span><span>
</span><span id="line-413"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156747"><span class="annot"><span class="annottext">m :: NodeName
</span><a href="#local-6989586621679156747"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156746"><span class="annot"><span class="annottext">i :: OutputIx
</span><a href="#local-6989586621679156746"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156745"><span class="annot"><span class="annottext">j :: OutputIx
</span><a href="#local-6989586621679156745"><span class="hs-identifier hs-var">j</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(NodeName, OutputIx, OutputIx)]
</span><a href="#local-6989586621679156744"><span class="hs-identifier hs-var">edges</span></a></span><span>
</span><span id="line-414"></span><span>                        </span><span class="hs-special">]</span><span>
</span><span id="line-415"></span><span>
</span><span id="line-416"></span><span class="hs-comment">-- | Function to compute the gradient of y w.r.t. each input.</span><span>
</span><span id="line-417"></span><span class="hs-comment">--</span><span>
</span><span id="line-418"></span><span class="hs-comment">-- Let y be an arbitrary tensor</span><span>
</span><span id="line-419"></span><span class="hs-comment">-- and [w_0, ..., w_n] be the output tensors of a node</span><span>
</span><span id="line-420"></span><span class="hs-comment">-- and [v_0, ..., v_n] be the input tensors of the same node.</span><span>
</span><span id="line-421"></span><span class="hs-comment">--</span><span>
</span><span id="line-422"></span><span class="hs-comment">-- Given [&#8706;y/&#8706;w_0, ..., &#8706;y/&#8706;w_n] and [v_0, ..., v_n], a GradientFunc computes</span><span>
</span><span id="line-423"></span><span class="hs-comment">-- [&#8706;y/&#8706;v_0, ..., &#8706;y/&#8706;v_n] for a particular op type.</span><span>
</span><span id="line-424"></span><span class="hs-comment">--</span><span>
</span><span id="line-425"></span><span class="hs-comment">-- A Nothing gradient is equivalent to zero (but allows for short circuiting</span><span>
</span><span id="line-426"></span><span class="hs-comment">-- computation when all the gradients for something are Nothing).</span><span>
</span><span id="line-427"></span><span class="hs-keyword">type</span><span> </span><span id="GradientFunc"><span class="annot"><a href="TensorFlow.Gradient.html#GradientFunc"><span class="hs-identifier hs-var">GradientFunc</span></a></span></span><span> </span><span id="local-6989586621679156743"><span class="annot"><a href="#local-6989586621679156743"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span>
</span><span id="line-428"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Output</span></span><span class="hs-special">]</span><span>
</span><span id="line-429"></span><span>                    </span><span class="hs-comment">-- ^ Input tensors.</span><span>
</span><span id="line-430"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Value</span></span><span> </span><span class="annot"><a href="#local-6989586621679156743"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-431"></span><span>                    </span><span class="hs-comment">-- ^ Gradient of y w.r.t. each output tensor.</span><span>
</span><span id="line-432"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679156743"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-433"></span><span>                    </span><span class="hs-comment">-- ^ Gradient of y w.r.t. each input tensor.</span><span>
</span><span id="line-434"></span><span>
</span><span id="line-435"></span><span>
</span><span id="line-436"></span><span class="hs-comment">-- TODO(fmayle): Assert the type is correct.</span><span>
</span><span id="line-437"></span><span class="hs-comment">-- | Create a Tensor from an Output.</span><span>
</span><span id="line-438"></span><span id="local-6989586621679157241"><span class="annot"><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-type">toT</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Output</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157241"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-439"></span><span id="toT"><span class="annot"><span class="annottext">toT :: Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var hs-var">toT</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Build Output -&gt; Tensor Build a
forall (v :: * -&gt; *) a. TensorKind v =&gt; v Output -&gt; Tensor v a
</span><span class="hs-identifier hs-var">Tensor</span></span><span> </span><span class="annot"><span class="annottext">(Build Output -&gt; Tensor Build a)
-&gt; (Output -&gt; Build Output) -&gt; Output -&gt; Tensor Build a
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Output -&gt; Build Output
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span>
</span><span id="line-440"></span><span>
</span><span id="line-441"></span><span>
</span><span id="line-442"></span><span class="hs-comment">-- | Wrapper around `TensorFlow.GenOps.Core.slice` that builds vectors from scalars for</span><span>
</span><span id="line-443"></span><span class="hs-comment">-- simple slicing operations.</span><span>
</span><span id="line-444"></span><span class="annot"><a href="TensorFlow.Gradient.html#flatSlice"><span class="hs-identifier hs-type">flatSlice</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679157116"><span class="annot"><a href="#local-6989586621679157116"><span class="hs-identifier hs-type">v1</span></a></span></span><span> </span><span id="local-6989586621679157117"><span class="annot"><a href="#local-6989586621679157117"><span class="hs-identifier hs-type">t</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><span class="hs-identifier hs-type">TensorType</span></span><span> </span><span class="annot"><a href="#local-6989586621679157117"><span class="hs-identifier hs-type">t</span></a></span><span>
</span><span id="line-445"></span><span>         </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679157116"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157117"><span class="hs-identifier hs-type">t</span></a></span><span>    </span><span class="hs-comment">-- ^ __input__</span><span>
</span><span id="line-446"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span>          </span><span class="hs-comment">-- ^ __begin__: specifies the offset into the first dimension of</span><span>
</span><span id="line-447"></span><span>                           </span><span class="hs-comment">-- 'input' to slice from.</span><span>
</span><span id="line-448"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span>          </span><span class="hs-comment">-- ^ __size__: specifies the number of elements of the first dimension</span><span>
</span><span id="line-449"></span><span>                           </span><span class="hs-comment">-- of 'input' to slice. If size is -1, all remaining elements in the dimension</span><span>
</span><span id="line-450"></span><span>                           </span><span class="hs-comment">-- are included in the slice (i.e. this is equivalent to setting</span><span>
</span><span id="line-451"></span><span>                           </span><span class="hs-comment">-- size = input.dim_size(0) - begin).</span><span>
</span><span id="line-452"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157117"><span class="hs-identifier hs-type">t</span></a></span><span> </span><span class="hs-comment">-- ^ __output__</span><span>
</span><span id="line-453"></span><span id="flatSlice"><span class="annot"><span class="annottext">flatSlice :: Tensor v1 t -&gt; Int32 -&gt; Int32 -&gt; Tensor Build t
</span><a href="TensorFlow.Gradient.html#flatSlice"><span class="hs-identifier hs-var hs-var">flatSlice</span></a></span></span><span> </span><span id="local-6989586621679156740"><span class="annot"><span class="annottext">t :: Tensor v1 t
</span><a href="#local-6989586621679156740"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621679156739"><span class="annot"><span class="annottext">begin :: Int32
</span><a href="#local-6989586621679156739"><span class="hs-identifier hs-var">begin</span></a></span></span><span> </span><span id="local-6989586621679156738"><span class="annot"><span class="annottext">size :: Int32
</span><a href="#local-6989586621679156738"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor v1 t
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build t
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t index.
(TensorType t, OneOf '[Int32, Int64] index) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 index -&gt; Tensor v'3 index -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.slice</span></span><span> </span><span class="annot"><span class="annottext">Tensor v1 t
</span><a href="#local-6989586621679156740"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int32
</span><a href="#local-6989586621679156739"><span class="hs-identifier hs-var">begin</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int32
</span><a href="#local-6989586621679156738"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-454"></span><span>
</span><span id="line-455"></span><span class="annot"><a href="TensorFlow.Gradient.html#nodeDefName"><span class="hs-identifier hs-type">nodeDefName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeName</span></span><span>
</span><span id="line-456"></span><span id="nodeDefName"><span class="annot"><span class="annottext">nodeDefName :: NodeDef -&gt; NodeName
</span><a href="TensorFlow.Gradient.html#nodeDefName"><span class="hs-identifier hs-var hs-var">nodeDefName</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Text -&gt; NodeName
</span><span class="hs-identifier hs-var">NodeName</span></span><span> </span><span class="annot"><span class="annottext">(Text -&gt; NodeName) -&gt; (NodeDef -&gt; Text) -&gt; NodeDef -&gt; NodeName
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text -&gt; NodeDef -&gt; Text
forall a s t b. FoldLike a s t a b -&gt; s -&gt; a
</span><span class="hs-identifier hs-var">view</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;name&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">name</span></span><span>
</span><span id="line-457"></span><span>
</span><span id="line-458"></span><span class="hs-comment">-- | Gradient helper for binary component wise operations</span><span>
</span><span id="line-459"></span><span class="hs-comment">-- See https://github.com/tensorflow/tensorflow/blob/e9de087fa7f59c39bbe12ac2c83c5547c83f746c/tensorflow/core/ops/math_grad.cc#L329</span><span>
</span><span id="line-460"></span><span id="local-6989586621679157104"><span id="local-6989586621679157105"><span class="annot"><a href="TensorFlow.Gradient.html#gradForBinaryCwise"><span class="hs-identifier hs-type">gradForBinaryCwise</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OneOf</span></span><span> </span><span class="hs-special">'</span><span class="hs-special">[</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Double</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Complex</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Complex</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Double</span></span><span> </span><span class="hs-special">]</span><span> </span><span class="annot"><a href="#local-6989586621679157105"><span class="hs-identifier hs-type">t</span></a></span><span>
</span><span id="line-461"></span><span>                      </span><span class="hs-special">)</span><span>
</span><span id="line-462"></span><span>                   </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679157104"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157105"><span class="hs-identifier hs-type">t</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679157104"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157105"><span class="hs-identifier hs-type">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-463"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679157104"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157105"><span class="hs-identifier hs-type">t</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679157104"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157105"><span class="hs-identifier hs-type">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-464"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157105"><span class="hs-identifier hs-type">t</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">]</span></span></span><span>
</span><span id="line-465"></span><span id="gradForBinaryCwise"><span class="annot"><span class="annottext">gradForBinaryCwise :: (Tensor v1 t, Tensor v1 t)
-&gt; (Tensor v1 t, Tensor v1 t) -&gt; [Maybe (Tensor Build t)]
</span><a href="TensorFlow.Gradient.html#gradForBinaryCwise"><span class="hs-identifier hs-var hs-var">gradForBinaryCwise</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156735"><span class="annot"><span class="annottext">x :: Tensor v1 t
</span><a href="#local-6989586621679156735"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156734"><span class="annot"><span class="annottext">gx :: Tensor v1 t
</span><a href="#local-6989586621679156734"><span class="hs-identifier hs-var">gx</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679156733"><span class="annot"><span class="annottext">y :: Tensor v1 t
</span><a href="#local-6989586621679156733"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156732"><span class="annot"><span class="annottext">gy :: Tensor v1 t
</span><a href="#local-6989586621679156732"><span class="hs-identifier hs-var">gy</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-466"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build t -&gt; Maybe (Tensor Build t)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build t
</span><a href="#local-6989586621679156731"><span class="hs-identifier hs-var">dx</span></a></span><span>
</span><span id="line-467"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build t -&gt; Maybe (Tensor Build t)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build t
</span><a href="#local-6989586621679156730"><span class="hs-identifier hs-var">dy</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-468"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-469"></span><span>    </span><span id="local-6989586621679156731"><span class="annot"><span class="annottext">dx :: Tensor Build t
</span><a href="#local-6989586621679156731"><span class="hs-identifier hs-var hs-var">dx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build t -&gt; Tensor Build Int32 -&gt; Tensor Build t
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor v1 t -&gt; Tensor Build Int32 -&gt; Tensor Build t
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="annot"><span class="annottext">Tensor v1 t
</span><a href="#local-6989586621679156734"><span class="hs-identifier hs-var">gx</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156729"><span class="hs-identifier hs-var">rx</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156728"><span class="hs-identifier hs-var">sx</span></a></span><span>
</span><span id="line-470"></span><span>    </span><span id="local-6989586621679156730"><span class="annot"><span class="annottext">dy :: Tensor Build t
</span><a href="#local-6989586621679156730"><span class="hs-identifier hs-var hs-var">dy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build t -&gt; Tensor Build Int32 -&gt; Tensor Build t
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor v1 t -&gt; Tensor Build Int32 -&gt; Tensor Build t
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="annot"><span class="annottext">Tensor v1 t
</span><a href="#local-6989586621679156732"><span class="hs-identifier hs-var">gy</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156727"><span class="hs-identifier hs-var">ry</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156726"><span class="hs-identifier hs-var">sy</span></a></span><span>
</span><span id="line-471"></span><span>    </span><span id="local-6989586621679156728"><span class="annot"><span class="annottext">sx :: Tensor Build Int32
</span><a href="#local-6989586621679156728"><span class="hs-identifier hs-var hs-var">sx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor v1 t -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor v1 t
</span><a href="#local-6989586621679156735"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-472"></span><span>    </span><span id="local-6989586621679156726"><span class="annot"><span class="annottext">sy :: Tensor Build Int32
</span><a href="#local-6989586621679156726"><span class="hs-identifier hs-var hs-var">sy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor v1 t -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor v1 t
</span><a href="#local-6989586621679156733"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-473"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679156729"><span class="annot"><span class="annottext">rx :: Tensor Build Int32
</span><a href="#local-6989586621679156729"><span class="hs-identifier hs-var">rx</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156727"><span class="annot"><span class="annottext">ry :: Tensor Build Int32
</span><a href="#local-6989586621679156727"><span class="hs-identifier hs-var">ry</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; (Tensor Build Int32, Tensor Build Int32)
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Int32, Int64] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; (Tensor Build t, Tensor Build t)
</span><span class="hs-identifier hs-var">broadcastGradientArgs</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156728"><span class="hs-identifier hs-var">sx</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156726"><span class="hs-identifier hs-var">sy</span></a></span><span>
</span><span id="line-474"></span><span>
</span><span id="line-475"></span><span class="hs-comment">-- | The gradient function for an op type.</span><span>
</span><span id="line-476"></span><span class="hs-comment">--</span><span>
</span><span id="line-477"></span><span class="hs-comment">-- These implementations should match their python counterparts in:</span><span>
</span><span id="line-478"></span><span class="hs-comment">-- third_party/tensorflow/python/ops/*_grad.py</span><span>
</span><span id="line-479"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-type">opGrad</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679157265"><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientCompatible"><span class="hs-identifier hs-type">GradientCompatible</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Text</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Gradient.html#GradientFunc"><span class="hs-identifier hs-type">GradientFunc</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-480"></span><span>
</span><span id="line-481"></span><span id="opGrad"><span class="annot"><span class="annottext">opGrad :: Text -&gt; GradientFunc a
</span><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var hs-var">opGrad</span></a></span></span><span> </span><span class="hs-string">&quot;Abs&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156725"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156725"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156724"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156724"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v :: * -&gt; *) a.
TensorKind v =&gt;
Tensor v a -&gt; Tensor Build a
</span><span class="hs-identifier hs-var">expr</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156724"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">*</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a
</span><span class="hs-identifier hs-var">signum</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156725"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-482"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Neg&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156721"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156721"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a
</span><span class="hs-identifier hs-var">negate</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Tensor Build a)
-&gt; Tensor Build a -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v :: * -&gt; *) a.
TensorKind v =&gt;
Tensor v a -&gt; Tensor Build a
</span><span class="hs-identifier hs-var">expr</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156721"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-483"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Relu&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156720"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156720"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156719"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156719"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Int16, Int32, Int64, Int8, Word16, Word32, Word64, Word8, Double,
    Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reluGrad</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156719"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156720"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-484"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;ReluGrad&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156718"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156718"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156717"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156717"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Int16, Int32, Int64, Int8, Word16, Word32, Word64, Word8, Double,
    Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reluGrad</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156717"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156718"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.zerosLike</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156718"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-485"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Tanh&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156716"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156716"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156715"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156715"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Complex Double, Complex Float, Word16, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">tanhGrad</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
OneOf '[Complex Double, Complex Float, Word16, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">tanh</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156716"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156715"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-486"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Sigmoid&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156714"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156714"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156713"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156713"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Complex Double, Complex Float, Word16, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sigmoidGrad</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
OneOf '[Complex Double, Complex Float, Word16, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sigmoid</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156714"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156713"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-487"></span><span>
</span><span id="line-488"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Concat&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span id="local-6989586621679156712"><span class="annot"><span class="annottext">_ix :: [Output]
</span><a href="#local-6989586621679156712"><span class="hs-identifier hs-var">_ix</span></a></span></span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156711"><span class="annot"><span class="annottext">dy :: Tensor Value a
</span><a href="#local-6989586621679156711"><span class="hs-identifier hs-var">dy</span></a></span></span><span class="hs-special">]</span><span>
</span><span id="line-489"></span><span>    </span><span class="hs-comment">-- Concat concatenates input tensors</span><span>
</span><span id="line-490"></span><span>    </span><span class="hs-comment">--   x1 of shape s1 = [k1, ..., ki_1, ..., kn]</span><span>
</span><span id="line-491"></span><span>    </span><span class="hs-comment">--   x2 of shape s2 = [k1, ..., ki_2, ..., kn]</span><span>
</span><span id="line-492"></span><span>    </span><span class="hs-comment">--    .           .     .          .        .</span><span>
</span><span id="line-493"></span><span>    </span><span class="hs-comment">--    .           .     .          .        .</span><span>
</span><span id="line-494"></span><span>    </span><span class="hs-comment">--    .           .     .          .        .</span><span>
</span><span id="line-495"></span><span>    </span><span class="hs-comment">--   xm of shape sm = [k1, ..., ki_m, ..., kn]</span><span>
</span><span id="line-496"></span><span>    </span><span class="hs-comment">--  along dimension i to an output tensor</span><span>
</span><span id="line-497"></span><span>    </span><span class="hs-comment">--   y  of shape sy = [k1, ..., k, ..., kn]</span><span>
</span><span id="line-498"></span><span>    </span><span class="hs-comment">--  where k = sum ki = sum [ki_1,...,ki_m]</span><span>
</span><span id="line-499"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-500"></span><span>    </span><span class="hs-comment">--  The incoming gradient dy from backpropagation is</span><span>
</span><span id="line-501"></span><span>    </span><span class="hs-comment">--   simply forwarded split across input tensors yielding dx.</span><span>
</span><span id="line-502"></span><span>    </span><span class="hs-comment">--   Forwarded gradients have shapes s = [s1, ..., sm].</span><span>
</span><span id="line-503"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156710"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Node -&gt; Node -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
-&gt; [Maybe (Tensor Build a)] -&gt; [Maybe (Tensor Build a)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v :: * -&gt; *) a.
TensorKind v =&gt;
Tensor v a -&gt; Tensor Build a
</span><span class="hs-identifier hs-var">expr</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156711"><span class="hs-identifier hs-var">dy</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-504"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">otherwise</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
-&gt; [Maybe (Tensor Build a)] -&gt; [Maybe (Tensor Build a)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; [Tensor Build a] -&gt; [Maybe (Tensor Build a)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Tensor Build a]
</span><a href="#local-6989586621679156709"><span class="hs-identifier hs-var">dx</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Build a] -&gt; [Tensor Build Int32] -&gt; [Tensor Build a]
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *).
[Tensor v'1 a] -&gt; [Tensor v'2 Int32] -&gt; [Tensor Build a]
</span><a href="#local-6989586621679156708"><span class="hs-operator hs-var">`reshapeZip`</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Build Int32]
</span><a href="#local-6989586621679156707"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-505"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-506"></span><span>    </span><span id="local-6989586621679156708"><span class="annot"><span class="annottext">reshapeZip :: [Tensor v'1 a] -&gt; [Tensor v'2 Int32] -&gt; [Tensor Build a]
</span><a href="#local-6989586621679156708"><span class="hs-identifier hs-var hs-var">reshapeZip</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Tensor v'1 a -&gt; Tensor v'2 Int32 -&gt; Tensor Build a)
-&gt; [Tensor v'1 a] -&gt; [Tensor v'2 Int32] -&gt; [Tensor Build a]
forall a b c. (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]
</span><span class="hs-identifier hs-var">zipWith</span></span><span> </span><span class="annot"><span class="annottext">Tensor v'1 a -&gt; Tensor v'2 Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span>
</span><span id="line-507"></span><span>    </span><span id="local-6989586621679156709"><span class="annot"><span class="annottext">dx :: [Tensor Build a]
</span><a href="#local-6989586621679156709"><span class="hs-identifier hs-var hs-var">dx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int64
-&gt; Tensor Value a
-&gt; Tensor Build Int32
-&gt; Tensor Build Int32
-&gt; [Tensor Build a]
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t tlen.
(TensorType t, OneOf '[Int32, Int64] tlen) =&gt;
Int64
-&gt; Tensor v'1 t
-&gt; Tensor v'2 tlen
-&gt; Tensor v'3 Int32
-&gt; [Tensor Build t]
</span><span class="hs-identifier hs-var">CoreOps.splitV</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Node -&gt; Int64
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><span class="hs-identifier hs-var">fromIntegral</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156710"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156711"><span class="hs-identifier hs-var">dy</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156704"><span class="hs-identifier hs-var">ki</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156703"><span class="hs-identifier hs-var">_i</span></a></span><span>
</span><span id="line-508"></span><span>    </span><span class="annot"><a href="#local-6989586621679156707"><span class="hs-identifier hs-type">s</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">]</span><span>
</span><span id="line-509"></span><span>    </span><span id="local-6989586621679156707"><span class="annot"><span class="annottext">s :: [Tensor Build Int32]
</span><a href="#local-6989586621679156707"><span class="hs-identifier hs-var hs-var">s</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Tensor Build Int32)
-&gt; [Tensor Build a] -&gt; [Tensor Build Int32]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Build a]
</span><a href="#local-6989586621679156702"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-510"></span><span>    </span><span class="annot"><a href="#local-6989586621679156702"><span class="hs-identifier hs-type">x</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-511"></span><span>    </span><span id="local-6989586621679156702"><span class="annot"><span class="annottext">x :: [Tensor Build a]
</span><a href="#local-6989586621679156702"><span class="hs-identifier hs-var hs-var">x</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Output -&gt; Tensor Build a) -&gt; [Output] -&gt; [Tensor Build a]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="annot"><span class="annottext">([Output] -&gt; [Tensor Build a]) -&gt; [Output] -&gt; [Tensor Build a]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[Output] -&gt; [Output]
forall a. [a] -&gt; [a]
</span><span class="hs-identifier hs-var">tail</span></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156712"><span class="hs-identifier hs-var">_ix</span></a></span><span>
</span><span id="line-512"></span><span>    </span><span class="hs-comment">-- i: concat dimension. Adjusted modulo n to handle negative indices.</span><span>
</span><span id="line-513"></span><span>    </span><span id="local-6989586621679156703"><span class="annot"><span class="annottext">_i :: Tensor Build Int32
</span><a href="#local-6989586621679156703"><span class="hs-identifier hs-var hs-var">_i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Output] -&gt; Output
forall a. [a] -&gt; a
</span><span class="hs-identifier hs-var">head</span></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156712"><span class="hs-identifier hs-var">_ix</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Int32, Int64, Word16, Word64, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.floorMod`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156698"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-514"></span><span>    </span><span id="local-6989586621679156697"><span class="annot"><span class="annottext">i :: Tensor Build Int32
</span><a href="#local-6989586621679156697"><span class="hs-identifier hs-var hs-var">i</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156703"><span class="hs-identifier hs-var">_i</span></a></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build Int32)
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">]</span><span>
</span><span id="line-515"></span><span>    </span><span class="hs-comment">-- sizes along concatenated dimension</span><span>
</span><span id="line-516"></span><span>    </span><span class="annot"><a href="#local-6989586621679156704"><span class="hs-identifier hs-type">ki</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span>
</span><span id="line-517"></span><span>    </span><span id="local-6989586621679156704"><span class="annot"><span class="annottext">ki :: Tensor Build Int32
</span><a href="#local-6989586621679156704"><span class="hs-identifier hs-var hs-var">ki</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; [Tensor Build Int32] -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Int32 -&gt; [Tensor v'2 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.concat</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">([Tensor Build Int32] -&gt; Tensor Build Int32)
-&gt; [Tensor Build Int32] -&gt; Tensor Build Int32
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build Int32)
-&gt; [Tensor Build Int32] -&gt; [Tensor Build Int32]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679156695"><span class="annot"><span class="annottext">t :: Tensor Build Int32
</span><a href="#local-6989586621679156695"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t index.
(TensorType t, OneOf '[Int32, Int64] index) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 index -&gt; Tensor v'3 index -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.slice</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156695"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156697"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build Int32)
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Tensor Build Int32]
</span><a href="#local-6989586621679156707"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-518"></span><span>    </span><span id="local-6989586621679156710"><span class="annot"><span class="annottext">m :: Node
</span><a href="#local-6989586621679156710"><span class="hs-identifier hs-var hs-var">m</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Tensor Build a] -&gt; Node
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Node
</span><span class="hs-identifier hs-var">length</span></span><span> </span><span class="annot"><span class="annottext">[Tensor Build a]
</span><a href="#local-6989586621679156702"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-519"></span><span>    </span><span id="local-6989586621679156698"><span class="annot"><span class="annottext">n :: Tensor Build Int32
</span><a href="#local-6989586621679156698"><span class="hs-identifier hs-var hs-var">n</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build Int32
</span><span class="hs-identifier hs-var">CoreOps.rank</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Tensor Build a] -&gt; Tensor Build a
forall a. [a] -&gt; a
</span><span class="hs-identifier hs-var">head</span></span><span> </span><span class="annot"><span class="annottext">[Tensor Build a]
</span><a href="#local-6989586621679156702"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-520"></span><span>
</span><span id="line-521"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Square&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156693"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156693"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156692"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156692"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-522"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): Handle complex numbers.</span><span>
</span><span id="line-523"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): The python code makes dz a control dependency of the 2*x</span><span>
</span><span id="line-524"></span><span>    </span><span class="hs-comment">-- (for performance reasons?). Will need to put these functions in the Build</span><span>
</span><span id="line-525"></span><span>    </span><span class="hs-comment">-- monad to replicate that.</span><span>
</span><span id="line-526"></span><span>    </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156692"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">*</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156693"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-527"></span><span>
</span><span id="line-528"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Gather&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156690"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156690"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156689"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156689"><span class="hs-identifier hs-var">indices</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156688"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156688"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-529"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): The python version uses a better performance implementation</span><span>
</span><span id="line-530"></span><span>    </span><span class="hs-comment">-- when the shape is known without having to run the graph.</span><span>
</span><span id="line-531"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): We shouldn't convert the result to a dense tensor. Sparse</span><span>
</span><span id="line-532"></span><span>    </span><span class="hs-comment">-- tensor support will require some thinking.</span><span>
</span><span id="line-533"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t tindices
       tnumsegments.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tindices,
 OneOf '[Int32, Int64] tnumsegments) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 tindices -&gt; Tensor v'3 tnumsegments -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.unsortedSegmentSum</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156686"><span class="hs-identifier hs-var">values</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156685"><span class="hs-identifier hs-var">indices'</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156684"><span class="hs-identifier hs-var">numRows</span></a></span><span>
</span><span id="line-534"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-535"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-536"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-537"></span><span>    </span><span class="hs-comment">-- TODO(gnezdo): Use colocateWith but it requires Build monad.</span><span>
</span><span id="line-538"></span><span>    </span><span id="local-6989586621679156683"><span class="annot"><span class="annottext">denseShape :: Tensor Build Int32
</span><a href="#local-6989586621679156683"><span class="hs-identifier hs-var hs-var">denseShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156690"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-539"></span><span>    </span><span id="local-6989586621679156684"><span class="annot"><span class="annottext">numRows :: Tensor Build Int32
</span><a href="#local-6989586621679156684"><span class="hs-identifier hs-var hs-var">numRows</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32
forall a (v :: * -&gt; *).
TensorType a =&gt;
Tensor v a -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#scalarize"><span class="hs-identifier hs-var">scalarize</span></a></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build Int32)
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Int32 -&gt; Int32 -&gt; Tensor Build Int32
forall (v1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v1 t -&gt; Int32 -&gt; Int32 -&gt; Tensor Build t
</span><a href="TensorFlow.Gradient.html#flatSlice"><span class="hs-identifier hs-var">flatSlice</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156683"><span class="hs-identifier hs-var">denseShape</span></a></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-540"></span><span>    </span><span id="local-6989586621679156682"><span class="annot"><span class="annottext">valuesShape :: Tensor Build Int32
</span><a href="#local-6989586621679156682"><span class="hs-identifier hs-var hs-var">valuesShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; [Tensor Build Int32] -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Int32 -&gt; [Tensor v'2 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.concat</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#allDimensions"><span class="hs-identifier hs-var">allDimensions</span></a></span><span>
</span><span id="line-541"></span><span>                                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Int32 -&gt; Int32 -&gt; Tensor Build Int32
forall (v1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v1 t -&gt; Int32 -&gt; Int32 -&gt; Tensor Build t
</span><a href="TensorFlow.Gradient.html#flatSlice"><span class="hs-identifier hs-var">flatSlice</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156683"><span class="hs-identifier hs-var">denseShape</span></a></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-542"></span><span>                                   </span><span class="hs-special">]</span><span>
</span><span id="line-543"></span><span>    </span><span id="local-6989586621679156686"><span class="annot"><span class="annottext">values :: Tensor Build a
</span><a href="#local-6989586621679156686"><span class="hs-identifier hs-var hs-var">values</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156688"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156682"><span class="hs-identifier hs-var">valuesShape</span></a></span><span>
</span><span id="line-544"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): This could be either Int32 or Int64.</span><span>
</span><span id="line-545"></span><span>    </span><span id="local-6989586621679156685"><span class="annot"><span class="annottext">indices' :: Tensor Build Int32
</span><a href="#local-6989586621679156685"><span class="hs-identifier hs-var hs-var">indices'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156689"><span class="hs-identifier hs-var">indices</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#allDimensions"><span class="hs-identifier hs-var">allDimensions</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span>
</span><span id="line-546"></span><span>
</span><span id="line-547"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Max&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156680"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156680"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156679"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156679"><span class="hs-identifier hs-var">indices</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156678"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156678"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-548"></span><span>    </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156677"><span class="hs-identifier hs-var">indicators</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.div`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156675"><span class="hs-identifier hs-var">numSelected</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">*</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156674"><span class="hs-identifier hs-var">dz'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-549"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-550"></span><span>    </span><span id="local-6989586621679156673"><span class="annot"><span class="annottext">sx :: Tensor Build Int32
</span><a href="#local-6989586621679156673"><span class="hs-identifier hs-var hs-var">sx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156680"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-551"></span><span>    </span><span id="local-6989586621679156672"><span class="annot"><span class="annottext">outputShapeKeptDims :: Tensor Build Int32
</span><a href="#local-6989586621679156672"><span class="hs-identifier hs-var hs-var">outputShapeKeptDims</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall t1 t2 (v1 :: * -&gt; *) (v2 :: * -&gt; *).
(OneOf '[Int32, Int64] t1, OneOf '[Int32, Int64] t2) =&gt;
Tensor v1 t1 -&gt; Tensor v2 t2 -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#reducedShape"><span class="hs-identifier hs-var">reducedShape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156673"><span class="hs-identifier hs-var">sx</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156679"><span class="hs-identifier hs-var">indices</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span>
</span><span id="line-552"></span><span>    </span><span id="local-6989586621679156671"><span class="annot"><span class="annottext">y :: Tensor Build a
</span><a href="#local-6989586621679156671"><span class="hs-identifier hs-var hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.max</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156680"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156679"><span class="hs-identifier hs-var">indices</span></a></span><span>
</span><span id="line-553"></span><span>    </span><span id="local-6989586621679156669"><span class="annot"><span class="annottext">y' :: Tensor Build a
</span><a href="#local-6989586621679156669"><span class="hs-identifier hs-var hs-var">y'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156671"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156672"><span class="hs-identifier hs-var">outputShapeKeptDims</span></a></span><span>
</span><span id="line-554"></span><span>    </span><span id="local-6989586621679156674"><span class="annot"><span class="annottext">dz' :: Tensor Build a
</span><a href="#local-6989586621679156674"><span class="hs-identifier hs-var hs-var">dz'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156678"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156672"><span class="hs-identifier hs-var">outputShapeKeptDims</span></a></span><span>
</span><span id="line-555"></span><span>    </span><span id="local-6989586621679156677"><span class="annot"><span class="annottext">indicators :: Tensor Build a
</span><a href="#local-6989586621679156677"><span class="hs-identifier hs-var hs-var">indicators</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) srcT dstT.
(TensorType srcT, TensorType dstT) =&gt;
Tensor v'1 srcT -&gt; Tensor Build dstT
</span><span class="hs-identifier hs-var">CoreOps.cast</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Bool -&gt; Tensor Build a)
-&gt; Tensor Build Bool -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build Bool
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Bool, ByteString, Int16, Int32,
    Int64, Int8, Word16, Word32, Word64, Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build Bool
</span><span class="hs-identifier hs-var">CoreOps.equal</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156669"><span class="hs-identifier hs-var">y'</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156680"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-556"></span><span>    </span><span id="local-6989586621679156675"><span class="annot"><span class="annottext">numSelected :: Tensor Build a
</span><a href="#local-6989586621679156675"><span class="hs-identifier hs-var hs-var">numSelected</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156677"><span class="hs-identifier hs-var">indicators</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156679"><span class="hs-identifier hs-var">indices</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156672"><span class="hs-identifier hs-var">outputShapeKeptDims</span></a></span><span>
</span><span id="line-557"></span><span>
</span><span id="line-558"></span><span class="hs-comment">-- Min and Max have identical gradient implementations.</span><span>
</span><span id="line-559"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Min&quot;</span><span> </span><span id="local-6989586621679156666"><span class="annot"><span class="annottext">u :: NodeDef
</span><a href="#local-6989586621679156666"><span class="hs-identifier hs-var">u</span></a></span></span><span> </span><span id="local-6989586621679156665"><span class="annot"><span class="annottext">v :: [Output]
</span><a href="#local-6989586621679156665"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621679156664"><span class="annot"><span class="annottext">w :: [Tensor Value a]
</span><a href="#local-6989586621679156664"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Text -&gt; GradientFunc a
forall a. GradientCompatible a =&gt; Text -&gt; GradientFunc a
</span><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;Max&quot;</span></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156666"><span class="hs-identifier hs-var">u</span></a></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156665"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156664"><span class="hs-identifier hs-var">w</span></a></span><span>
</span><span id="line-560"></span><span>
</span><span id="line-561"></span><span class="hs-comment">-- Element wise maximum gradient</span><span>
</span><span id="line-562"></span><span class="hs-comment">-- See https://github.com/tensorflow/tensorflow/blob/e9de087fa7f59c39bbe12ac2c83c5547c83f746c/tensorflow/core/ops/math_grad.cc#L473</span><span>
</span><span id="line-563"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Maximum&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156663"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156663"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156662"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156662"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156661"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156661"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-564"></span><span>    </span><span class="annot"><span class="annottext">(Tensor Build a, Tensor Build a)
-&gt; (Tensor Build a, Tensor Build a) -&gt; [Maybe (Tensor Build a)]
forall t (v1 :: * -&gt; *).
OneOf
  '[Int32, Int64, Float, Double, Complex Float, Complex Double] t =&gt;
(Tensor v1 t, Tensor v1 t)
-&gt; (Tensor v1 t, Tensor v1 t) -&gt; [Maybe (Tensor Build t)]
</span><a href="TensorFlow.Gradient.html#gradForBinaryCwise"><span class="hs-identifier hs-var">gradForBinaryCwise</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156663"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156660"><span class="hs-identifier hs-var">gx</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156662"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156659"><span class="hs-identifier hs-var">gy</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-565"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-566"></span><span>    </span><span id="local-6989586621679156658"><span class="annot"><span class="annottext">xmask :: Tensor Build Bool
</span><a href="#local-6989586621679156658"><span class="hs-identifier hs-var hs-var">xmask</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build Bool
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Int16, Int32, Int64, Int8, Word16, Word32, Word64, Word8, Double,
    Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build Bool
</span><span class="hs-identifier hs-var">CoreOps.greaterEqual</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156663"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156662"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-567"></span><span>    </span><span id="local-6989586621679156660"><span class="annot"><span class="annottext">gx :: Tensor Build a
</span><a href="#local-6989586621679156660"><span class="hs-identifier hs-var hs-var">gx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Bool -&gt; Tensor v'2 t -&gt; Tensor v'3 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.select</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
</span><a href="#local-6989586621679156658"><span class="hs-identifier hs-var">xmask</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156661"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.zerosLike</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156661"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-568"></span><span>    </span><span id="local-6989586621679156659"><span class="annot"><span class="annottext">gy :: Tensor Build a
</span><a href="#local-6989586621679156659"><span class="hs-identifier hs-var hs-var">gy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Bool -&gt; Tensor v'2 t -&gt; Tensor v'3 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.select</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Bool -&gt; Tensor Build Bool
forall (v'1 :: * -&gt; *). Tensor v'1 Bool -&gt; Tensor Build Bool
</span><span class="hs-identifier hs-var">CoreOps.logicalNot</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
</span><a href="#local-6989586621679156658"><span class="hs-identifier hs-var">xmask</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156661"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.zerosLike</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156661"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-569"></span><span>
</span><span id="line-570"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Sum&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156654"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156654"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156653"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156653"><span class="hs-identifier hs-var">indices</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156652"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156652"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-571"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.tile</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156650"><span class="hs-identifier hs-var">grad</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156649"><span class="hs-identifier hs-var">tileScaling</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-572"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-573"></span><span>    </span><span class="hs-comment">-- TODO(gnezdo): Implement the fast-path from math_grad._SumGrad.</span><span>
</span><span id="line-574"></span><span>    </span><span id="local-6989586621679156648"><span class="annot"><span class="annottext">sx :: Tensor Build Int32
</span><a href="#local-6989586621679156648"><span class="hs-identifier hs-var hs-var">sx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156654"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-575"></span><span>    </span><span id="local-6989586621679156647"><span class="annot"><span class="annottext">outputShapeKeptDims :: Tensor Build Int32
</span><a href="#local-6989586621679156647"><span class="hs-identifier hs-var hs-var">outputShapeKeptDims</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall t1 t2 (v1 :: * -&gt; *) (v2 :: * -&gt; *).
(OneOf '[Int32, Int64] t1, OneOf '[Int32, Int64] t2) =&gt;
Tensor v1 t1 -&gt; Tensor v2 t2 -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#reducedShape"><span class="hs-identifier hs-var">reducedShape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156648"><span class="hs-identifier hs-var">sx</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156653"><span class="hs-identifier hs-var">indices</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span>
</span><span id="line-576"></span><span>    </span><span id="local-6989586621679156649"><span class="annot"><span class="annottext">tileScaling :: Tensor Build Int32
</span><a href="#local-6989586621679156649"><span class="hs-identifier hs-var hs-var">tileScaling</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v1 :: * -&gt; *) (v2 :: * -&gt; *).
Tensor v1 Int32 -&gt; Tensor v2 Int32 -&gt; Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#safeShapeDiv"><span class="hs-identifier hs-var">safeShapeDiv</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156648"><span class="hs-identifier hs-var">sx</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156647"><span class="hs-identifier hs-var">outputShapeKeptDims</span></a></span><span>
</span><span id="line-577"></span><span>    </span><span id="local-6989586621679156650"><span class="annot"><span class="annottext">grad :: Tensor Build a
</span><a href="#local-6989586621679156650"><span class="hs-identifier hs-var hs-var">grad</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156652"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156647"><span class="hs-identifier hs-var">outputShapeKeptDims</span></a></span><span>
</span><span id="line-578"></span><span>
</span><span id="line-579"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Mean&quot;</span><span> </span><span id="local-6989586621679156645"><span class="annot"><span class="annottext">u :: NodeDef
</span><a href="#local-6989586621679156645"><span class="hs-identifier hs-var">u</span></a></span></span><span> </span><span id="local-6989586621679156644"><span class="annot"><span class="annottext">v :: [Output]
</span><a href="#local-6989586621679156644"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156643"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156643"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679156642"><span class="annot"><span class="annottext">w :: [Tensor Value a]
</span><a href="#local-6989586621679156642"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-580"></span><span>    </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156641"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.div`</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.stopGradient</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Tensor Build a)
-&gt; Tensor Build a -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) srcT dstT.
(TensorType srcT, TensorType dstT) =&gt;
Tensor v'1 srcT -&gt; Tensor Build dstT
</span><span class="hs-identifier hs-var">CoreOps.cast</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build a)
-&gt; Tensor Build Int32 -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156639"><span class="hs-identifier hs-var">factor</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-581"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-582"></span><span>    </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Just</span></span><span> </span><span id="local-6989586621679156641"><span class="annot"><span class="annottext">dz :: Tensor Build a
</span><a href="#local-6989586621679156641"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Nothing</span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Text -&gt; GradientFunc a
forall a. GradientCompatible a =&gt; Text -&gt; GradientFunc a
</span><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;Sum&quot;</span></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156645"><span class="hs-identifier hs-var">u</span></a></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156644"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156642"><span class="hs-identifier hs-var">w</span></a></span><span>
</span><span id="line-583"></span><span>    </span><span id="local-6989586621679156638"><span class="annot"><span class="annottext">inputShape :: Tensor Build Int32
</span><a href="#local-6989586621679156638"><span class="hs-identifier hs-var hs-var">inputShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156643"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-584"></span><span>    </span><span id="local-6989586621679156637"><span class="annot"><span class="annottext">outputShape :: Tensor Build Int32
</span><a href="#local-6989586621679156637"><span class="hs-identifier hs-var hs-var">outputShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156641"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-585"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): Add fast path when shape is known.</span><span>
</span><span id="line-586"></span><span>    </span><span id="local-6989586621679156636"><span class="annot"><span class="annottext">inputSize :: Tensor Build Int32
</span><a href="#local-6989586621679156636"><span class="hs-identifier hs-var hs-var">inputSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.prod</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156638"><span class="hs-identifier hs-var">inputShape</span></a></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build Int32)
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#rangeOfRank"><span class="hs-identifier hs-var">rangeOfRank</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156638"><span class="hs-identifier hs-var">inputShape</span></a></span><span>
</span><span id="line-587"></span><span>    </span><span id="local-6989586621679156633"><span class="annot"><span class="annottext">outputSize :: Tensor Build Int32
</span><a href="#local-6989586621679156633"><span class="hs-identifier hs-var hs-var">outputSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.prod</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156637"><span class="hs-identifier hs-var">outputShape</span></a></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build Int32)
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#rangeOfRank"><span class="hs-identifier hs-var">rangeOfRank</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156637"><span class="hs-identifier hs-var">outputShape</span></a></span><span>
</span><span id="line-588"></span><span>    </span><span id="local-6989586621679156639"><span class="annot"><span class="annottext">factor :: Tensor Build Int32
</span><a href="#local-6989586621679156639"><span class="hs-identifier hs-var hs-var">factor</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v1 :: * -&gt; *) (v2 :: * -&gt; *).
Tensor v1 Int32 -&gt; Tensor v2 Int32 -&gt; Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#safeShapeDiv"><span class="hs-identifier hs-var">safeShapeDiv</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156636"><span class="hs-identifier hs-var">inputSize</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156633"><span class="hs-identifier hs-var">outputSize</span></a></span><span>
</span><span id="line-589"></span><span>
</span><span id="line-590"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Add&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156632"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156632"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156631"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156631"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156630"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156630"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-591"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156630"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156629"><span class="hs-identifier hs-var">rx</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156628"><span class="hs-identifier hs-var">sx</span></a></span><span>
</span><span id="line-592"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156630"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156627"><span class="hs-identifier hs-var">ry</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156626"><span class="hs-identifier hs-var">sy</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-593"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-594"></span><span>    </span><span id="local-6989586621679156628"><span class="annot"><span class="annottext">sx :: Tensor Build Int32
</span><a href="#local-6989586621679156628"><span class="hs-identifier hs-var hs-var">sx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156632"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-595"></span><span>    </span><span id="local-6989586621679156626"><span class="annot"><span class="annottext">sy :: Tensor Build Int32
</span><a href="#local-6989586621679156626"><span class="hs-identifier hs-var hs-var">sy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156631"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-596"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679156629"><span class="annot"><span class="annottext">rx :: Tensor Build Int32
</span><a href="#local-6989586621679156629"><span class="hs-identifier hs-var">rx</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156627"><span class="annot"><span class="annottext">ry :: Tensor Build Int32
</span><a href="#local-6989586621679156627"><span class="hs-identifier hs-var">ry</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; (Tensor Build Int32, Tensor Build Int32)
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Int32, Int64] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; (Tensor Build t, Tensor Build t)
</span><span class="hs-identifier hs-var">broadcastGradientArgs</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156628"><span class="hs-identifier hs-var">sx</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156626"><span class="hs-identifier hs-var">sy</span></a></span><span>
</span><span id="line-597"></span><span>
</span><span id="line-598"></span><span class="hs-comment">-- Copies the gradients to all inputs</span><span>
</span><span id="line-599"></span><span class="hs-comment">-- Not broadcasting</span><span>
</span><span id="line-600"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;AddN&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span id="local-6989586621679156625"><span class="annot"><span class="annottext">inputs :: [Output]
</span><a href="#local-6989586621679156625"><span class="hs-identifier hs-var">inputs</span></a></span></span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156624"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156624"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-601"></span><span>    </span><span class="annot"><span class="annottext">(Output -&gt; Maybe (Tensor Build a))
-&gt; [Output] -&gt; [Maybe (Tensor Build a)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe (Tensor Build a) -&gt; Output -&gt; Maybe (Tensor Build a)
forall a b. a -&gt; b -&gt; a
</span><span class="hs-identifier hs-var">const</span></span><span> </span><span class="annot"><span class="annottext">(Maybe (Tensor Build a) -&gt; Output -&gt; Maybe (Tensor Build a))
-&gt; (Tensor Value a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Value a
-&gt; Output
-&gt; Maybe (Tensor Build a)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; (Tensor Value a -&gt; Tensor Build a)
-&gt; Tensor Value a
-&gt; Maybe (Tensor Build a)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v :: * -&gt; *) a.
TensorKind v =&gt;
Tensor v a -&gt; Tensor Build a
</span><span class="hs-identifier hs-var">expr</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156624"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156625"><span class="hs-identifier hs-var">inputs</span></a></span><span>
</span><span id="line-602"></span><span>
</span><span id="line-603"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Sub&quot;</span><span> </span><span id="local-6989586621679156622"><span class="annot"><span class="annottext">u :: NodeDef
</span><a href="#local-6989586621679156622"><span class="hs-identifier hs-var">u</span></a></span></span><span> </span><span id="local-6989586621679156621"><span class="annot"><span class="annottext">v :: [Output]
</span><a href="#local-6989586621679156621"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621679156620"><span class="annot"><span class="annottext">w :: [Tensor Value a]
</span><a href="#local-6989586621679156620"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-604"></span><span>    </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156619"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156618"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-605"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-606"></span><span>    </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Just</span></span><span> </span><span id="local-6989586621679156619"><span class="annot"><span class="annottext">x :: Tensor Build a
</span><a href="#local-6989586621679156619"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Just</span></span><span> </span><span id="local-6989586621679156618"><span class="annot"><span class="annottext">y :: Tensor Build a
</span><a href="#local-6989586621679156618"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Text -&gt; GradientFunc a
forall a. GradientCompatible a =&gt; Text -&gt; GradientFunc a
</span><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;Add&quot;</span></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156622"><span class="hs-identifier hs-var">u</span></a></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156621"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156620"><span class="hs-identifier hs-var">w</span></a></span><span>
</span><span id="line-607"></span><span>
</span><span id="line-608"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;SoftmaxCrossEntropyWithLogits&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156617"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156617"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156616"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156616"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156615"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156615"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-609"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall t (v1 :: * -&gt; *) (v2 :: * -&gt; *).
TensorType t =&gt;
Tensor v1 t -&gt; Tensor v2 Int32 -&gt; Tensor Build t
</span><a href="TensorFlow.Ops.html#expandDims"><span class="hs-identifier hs-var">expandDims</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156615"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">*</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a, Tensor Build a) -&gt; Tensor Build a
forall a b. (a, b) -&gt; b
</span><span class="hs-identifier hs-var">snd</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
-&gt; Tensor Build a -&gt; (Tensor Build a, Tensor Build a)
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; (Tensor Build t, Tensor Build t)
</span><span class="hs-identifier hs-var">softmaxCrossEntropyWithLogits</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156617"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156616"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-610"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-611"></span><span>
</span><span id="line-612"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Mul&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156614"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156614"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156613"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156613"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156612"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156612"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-613"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): Handle complex numbers.</span><span>
</span><span id="line-614"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156612"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156613"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156611"><span class="hs-identifier hs-var">rx</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156610"><span class="hs-identifier hs-var">sx</span></a></span><span>
</span><span id="line-615"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156614"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156612"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156609"><span class="hs-identifier hs-var">ry</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156608"><span class="hs-identifier hs-var">sy</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-616"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-617"></span><span>    </span><span id="local-6989586621679156610"><span class="annot"><span class="annottext">sx :: Tensor Build Int32
</span><a href="#local-6989586621679156610"><span class="hs-identifier hs-var hs-var">sx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156614"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-618"></span><span>    </span><span id="local-6989586621679156608"><span class="annot"><span class="annottext">sy :: Tensor Build Int32
</span><a href="#local-6989586621679156608"><span class="hs-identifier hs-var hs-var">sy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156613"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-619"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679156611"><span class="annot"><span class="annottext">rx :: Tensor Build Int32
</span><a href="#local-6989586621679156611"><span class="hs-identifier hs-var">rx</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156609"><span class="annot"><span class="annottext">ry :: Tensor Build Int32
</span><a href="#local-6989586621679156609"><span class="hs-identifier hs-var">ry</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; (Tensor Build Int32, Tensor Build Int32)
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Int32, Int64] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; (Tensor Build t, Tensor Build t)
</span><span class="hs-identifier hs-var">broadcastGradientArgs</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156610"><span class="hs-identifier hs-var">sx</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156608"><span class="hs-identifier hs-var">sy</span></a></span><span>
</span><span id="line-620"></span><span>
</span><span id="line-621"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Div&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156607"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156607"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156606"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156606"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156605"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156605"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-622"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): Handle complex numbers.</span><span>
</span><span id="line-623"></span><span>    </span><span class="hs-comment">-- TODO(gnezdo): Provide Fractional instance and use '/' instead of div.</span><span>
</span><span id="line-624"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156605"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.div`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156606"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156604"><span class="hs-identifier hs-var">rx</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156603"><span class="hs-identifier hs-var">sx</span></a></span><span>
</span><span id="line-625"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156605"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a
</span><span class="hs-identifier hs-var">negate</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156607"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.div`</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156606"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">*</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156606"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-626"></span><span>                         </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156602"><span class="hs-identifier hs-var">ry</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-627"></span><span>                </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156601"><span class="hs-identifier hs-var">sy</span></a></span><span>
</span><span id="line-628"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-629"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-630"></span><span>    </span><span id="local-6989586621679156603"><span class="annot"><span class="annottext">sx :: Tensor Build Int32
</span><a href="#local-6989586621679156603"><span class="hs-identifier hs-var hs-var">sx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156607"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-631"></span><span>    </span><span id="local-6989586621679156601"><span class="annot"><span class="annottext">sy :: Tensor Build Int32
</span><a href="#local-6989586621679156601"><span class="hs-identifier hs-var hs-var">sy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156606"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-632"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679156604"><span class="annot"><span class="annottext">rx :: Tensor Build Int32
</span><a href="#local-6989586621679156604"><span class="hs-identifier hs-var">rx</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679156602"><span class="annot"><span class="annottext">ry :: Tensor Build Int32
</span><a href="#local-6989586621679156602"><span class="hs-identifier hs-var">ry</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; (Tensor Build Int32, Tensor Build Int32)
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Int32, Int64] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; (Tensor Build t, Tensor Build t)
</span><span class="hs-identifier hs-var">broadcastGradientArgs</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156603"><span class="hs-identifier hs-var">sx</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156601"><span class="hs-identifier hs-var">sy</span></a></span><span>
</span><span id="line-633"></span><span>
</span><span id="line-634"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;MatMul&quot;</span><span> </span><span id="local-6989586621679156600"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156600"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156599"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156599"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156598"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156598"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156597"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-635"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156596"><span class="annot"><span class="annottext">transposeA :: Bool
</span><a href="#local-6989586621679156596"><span class="hs-identifier hs-var hs-var">transposeA</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Bool
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156600"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;transpose_a&quot;</span></span><span>
</span><span id="line-636"></span><span>        </span><span id="local-6989586621679156594"><span class="annot"><span class="annottext">transposeB :: Bool
</span><a href="#local-6989586621679156594"><span class="hs-identifier hs-var hs-var">transposeB</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Bool
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156600"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;transpose_b&quot;</span></span><span>
</span><span id="line-637"></span><span>        </span><span id="local-6989586621679156593"><span class="annot"><span class="annottext">transAttrs :: a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156593"><span class="hs-identifier hs-var hs-var">transAttrs</span></a></span></span><span> </span><span id="local-6989586621679156592"><span class="annot"><span class="annottext">a :: a
</span><a href="#local-6989586621679156592"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679156591"><span class="annot"><span class="annottext">b :: a
</span><a href="#local-6989586621679156591"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-638"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef a
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;transpose_a&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef a)
-&gt; a -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156592"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef a
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;transpose_b&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef a)
-&gt; a -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156591"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-639"></span><span>    </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156596"><span class="hs-identifier hs-var">transposeA</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156594"><span class="hs-identifier hs-var">transposeB</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-640"></span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-641"></span><span>           </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156593"><span class="hs-identifier hs-var">transAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156598"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-642"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156593"><span class="hs-identifier hs-var">transAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156599"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-643"></span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-644"></span><span>           </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156598"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-645"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156593"><span class="hs-identifier hs-var">transAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156599"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-646"></span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-647"></span><span>           </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156593"><span class="hs-identifier hs-var">transAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156598"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-648"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156599"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-649"></span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-650"></span><span>           </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156593"><span class="hs-identifier hs-var">transAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156598"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-651"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">matMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156593"><span class="hs-identifier hs-var">transAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156597"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156599"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-652"></span><span>
</span><span id="line-653"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;BatchMatMul&quot;</span><span> </span><span id="local-6989586621679156590"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156590"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156589"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156589"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156588"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156588"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156587"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-654"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156586"><span class="annot"><span class="annottext">adjX :: Bool
</span><a href="#local-6989586621679156586"><span class="hs-identifier hs-var hs-var">adjX</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Bool
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156590"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;adj_x&quot;</span></span><span>
</span><span id="line-655"></span><span>        </span><span id="local-6989586621679156585"><span class="annot"><span class="annottext">adjY :: Bool
</span><a href="#local-6989586621679156585"><span class="hs-identifier hs-var hs-var">adjY</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Bool
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156590"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;adj_y&quot;</span></span><span>
</span><span id="line-656"></span><span>        </span><span id="local-6989586621679156584"><span class="annot"><span class="annottext">adjAttrs :: a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156584"><span class="hs-identifier hs-var hs-var">adjAttrs</span></a></span></span><span> </span><span id="local-6989586621679156583"><span class="annot"><span class="annottext">a :: a
</span><a href="#local-6989586621679156583"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679156582"><span class="annot"><span class="annottext">b :: a
</span><a href="#local-6989586621679156582"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-657"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef a
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;adj_x&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef a)
-&gt; a -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156583"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef a
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;adj_y&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef a)
-&gt; a -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679156582"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-658"></span><span>    </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156586"><span class="hs-identifier hs-var">adjX</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156585"><span class="hs-identifier hs-var">adjY</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-659"></span><span>        </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-660"></span><span>            </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156584"><span class="hs-identifier hs-var">adjAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156588"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-661"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156584"><span class="hs-identifier hs-var">adjAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156589"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-662"></span><span>        </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-663"></span><span>            </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156588"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-664"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156584"><span class="hs-identifier hs-var">adjAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156589"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-665"></span><span>        </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">False</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-666"></span><span>            </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156584"><span class="hs-identifier hs-var">adjAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156588"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-667"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156589"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-668"></span><span>        </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">True</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-669"></span><span>            </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156584"><span class="hs-identifier hs-var">adjAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156588"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-670"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int32, Int64, Word16, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef) -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchMatMul'</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; OpDef -&gt; OpDef
forall a a. (Attribute a, Attribute a) =&gt; a -&gt; a -&gt; OpDef -&gt; OpDef
</span><a href="#local-6989586621679156584"><span class="hs-identifier hs-var">adjAttrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156587"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156589"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-671"></span><span>
</span><span id="line-672"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Transpose&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156579"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156579"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156578"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156578"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-673"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.transpose</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156578"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-674"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
OneOf '[Int32, Int64] t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.invertPermutation</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156579"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span>
</span><span id="line-675"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-676"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-677"></span><span>
</span><span id="line-678"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Conv2D&quot;</span><span> </span><span id="local-6989586621679156575"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156575"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156574"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156574"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156573"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156573"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156572"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156572"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-679"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor Build Int32
-&gt; Tensor Build a
-&gt; Tensor Value a
-&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
OneOf '[Int32, Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor v'1 Int32
-&gt; Tensor v'2 t
-&gt; Tensor v'3 t
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.conv2DBackpropInput'</span></span><span>
</span><span id="line-680"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156570"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-681"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef Bool
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;use_cudnn_on_gpu&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef Bool)
-&gt; Bool -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156569"><span class="hs-identifier hs-var">useCudnnOnGpu</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-682"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156568"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-683"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156567"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156574"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156573"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156572"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-684"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor Build a
-&gt; Tensor Build Int32
-&gt; Tensor Value a
-&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor v'1 t
-&gt; Tensor v'2 Int32
-&gt; Tensor v'3 t
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.conv2DBackpropFilter'</span></span><span>
</span><span id="line-685"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156570"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-686"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef Bool
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;use_cudnn_on_gpu&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef Bool)
-&gt; Bool -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156569"><span class="hs-identifier hs-var">useCudnnOnGpu</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-687"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156568"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-688"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156567"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156574"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156573"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156572"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-689"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-690"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-691"></span><span>    </span><span id="local-6989586621679156570"><span class="annot"><span class="annottext">strides :: [Int64]
</span><a href="#local-6989586621679156570"><span class="hs-identifier hs-var hs-var">strides</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; [Int64]
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156575"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">]</span><span>
</span><span id="line-692"></span><span>    </span><span id="local-6989586621679156567"><span class="annot"><span class="annottext">padding :: ByteString
</span><a href="#local-6989586621679156567"><span class="hs-identifier hs-var hs-var">padding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156575"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;padding&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-693"></span><span>    </span><span id="local-6989586621679156569"><span class="annot"><span class="annottext">useCudnnOnGpu :: Bool
</span><a href="#local-6989586621679156569"><span class="hs-identifier hs-var hs-var">useCudnnOnGpu</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Bool
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156575"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;use_cudnn_on_gpu&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-694"></span><span>    </span><span id="local-6989586621679156568"><span class="annot"><span class="annottext">dataFormat :: ByteString
</span><a href="#local-6989586621679156568"><span class="hs-identifier hs-var hs-var">dataFormat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156575"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-695"></span><span>
</span><span id="line-696"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Conv2DBackpropInput&quot;</span><span> </span><span id="local-6989586621679156565"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156565"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156564"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156564"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156563"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156563"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156562"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156562"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-697"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-698"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor Value a
-&gt; Tensor Build Int32
-&gt; Tensor Build a
-&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor v'1 t
-&gt; Tensor v'2 Int32
-&gt; Tensor v'3 t
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.conv2DBackpropFilter'</span></span><span>
</span><span id="line-699"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156561"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-700"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef Bool
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;use_cudnn_on_gpu&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef Bool)
-&gt; Bool -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156560"><span class="hs-identifier hs-var">useCudnnOnGpu</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-701"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156559"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-702"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156558"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156562"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156564"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156563"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-703"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString -&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Int32, Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.conv2D'</span></span><span>
</span><span id="line-704"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156561"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-705"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef Bool
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;use_cudnn_on_gpu&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef Bool)
-&gt; Bool -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156560"><span class="hs-identifier hs-var">useCudnnOnGpu</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-706"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156559"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-707"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156558"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156562"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156564"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-708"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-709"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-710"></span><span>    </span><span id="local-6989586621679156561"><span class="annot"><span class="annottext">strides :: [Int64]
</span><a href="#local-6989586621679156561"><span class="hs-identifier hs-var hs-var">strides</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; [Int64]
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156565"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">]</span><span>
</span><span id="line-711"></span><span>    </span><span id="local-6989586621679156558"><span class="annot"><span class="annottext">padding :: ByteString
</span><a href="#local-6989586621679156558"><span class="hs-identifier hs-var hs-var">padding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156565"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;padding&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-712"></span><span>    </span><span id="local-6989586621679156560"><span class="annot"><span class="annottext">useCudnnOnGpu :: Bool
</span><a href="#local-6989586621679156560"><span class="hs-identifier hs-var hs-var">useCudnnOnGpu</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Bool
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156565"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;use_cudnn_on_gpu&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-713"></span><span>    </span><span id="local-6989586621679156559"><span class="annot"><span class="annottext">dataFormat :: ByteString
</span><a href="#local-6989586621679156559"><span class="hs-identifier hs-var hs-var">dataFormat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156565"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-714"></span><span>
</span><span id="line-715"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;DepthwiseConv2dNative&quot;</span><span> </span><span id="local-6989586621679156556"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156556"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156555"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156555"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156554"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156554"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156553"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156553"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-716"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor Build Int32
-&gt; Tensor Build a
-&gt; Tensor Value a
-&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor v'1 Int32
-&gt; Tensor v'2 t
-&gt; Tensor v'3 t
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.depthwiseConv2dNativeBackpropInput'</span></span><span>
</span><span id="line-717"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156551"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-718"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156550"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-719"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156549"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156555"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156554"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156553"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-720"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor Build a
-&gt; Tensor Build Int32
-&gt; Tensor Value a
-&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor v'1 t
-&gt; Tensor v'2 Int32
-&gt; Tensor v'3 t
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.depthwiseConv2dNativeBackpropFilter'</span></span><span>
</span><span id="line-721"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156551"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-722"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156550"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-723"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156549"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156555"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156554"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156553"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-724"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-725"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-726"></span><span>    </span><span id="local-6989586621679156551"><span class="annot"><span class="annottext">strides :: [Int64]
</span><a href="#local-6989586621679156551"><span class="hs-identifier hs-var hs-var">strides</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; [Int64]
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156556"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">]</span><span>
</span><span id="line-727"></span><span>    </span><span id="local-6989586621679156549"><span class="annot"><span class="annottext">padding :: ByteString
</span><a href="#local-6989586621679156549"><span class="hs-identifier hs-var hs-var">padding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156556"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;padding&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-728"></span><span>    </span><span id="local-6989586621679156550"><span class="annot"><span class="annottext">dataFormat :: ByteString
</span><a href="#local-6989586621679156550"><span class="hs-identifier hs-var hs-var">dataFormat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156556"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-729"></span><span>
</span><span id="line-730"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;DepthwiseConv2dNativeBackpropInput&quot;</span><span> </span><span id="local-6989586621679156547"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156547"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156546"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156546"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156545"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156545"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156544"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156544"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-731"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-732"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor Value a
-&gt; Tensor Build Int32
-&gt; Tensor Build a
-&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor v'1 t
-&gt; Tensor v'2 Int32
-&gt; Tensor v'3 t
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.depthwiseConv2dNativeBackpropFilter'</span></span><span>
</span><span id="line-733"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156543"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-734"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156542"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-735"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156541"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156544"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156546"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156545"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-736"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString -&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString -&gt; Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.depthwiseConv2dNative'</span></span><span>
</span><span id="line-737"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156543"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-738"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156542"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-739"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156541"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156544"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156546"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-740"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-741"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-742"></span><span>    </span><span id="local-6989586621679156543"><span class="annot"><span class="annottext">strides :: [Int64]
</span><a href="#local-6989586621679156543"><span class="hs-identifier hs-var hs-var">strides</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; [Int64]
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156547"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">]</span><span>
</span><span id="line-743"></span><span>    </span><span id="local-6989586621679156541"><span class="annot"><span class="annottext">padding :: ByteString
</span><a href="#local-6989586621679156541"><span class="hs-identifier hs-var hs-var">padding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156547"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;padding&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-744"></span><span>    </span><span id="local-6989586621679156542"><span class="annot"><span class="annottext">dataFormat :: ByteString
</span><a href="#local-6989586621679156542"><span class="hs-identifier hs-var hs-var">dataFormat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156547"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-745"></span><span>
</span><span id="line-746"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;MaxPool&quot;</span><span> </span><span id="local-6989586621679156539"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156539"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156538"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156538"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156537"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156537"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-747"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor Build a
-&gt; Tensor Build a
-&gt; Tensor Value a
-&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
OneOf
  '[Int16, Int32, Int64, Int8, Word16, Word32, Word64, Word8, Double,
    Float]
  t =&gt;
(OpDef -&gt; OpDef)
-&gt; ByteString
-&gt; Tensor v'1 t
-&gt; Tensor v'2 t
-&gt; Tensor v'3 t
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.maxPoolGrad'</span></span><span>
</span><span id="line-748"></span><span>                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;ksize&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156535"><span class="hs-identifier hs-var">ksize</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-749"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef [Int64]
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Int64])
-&gt; [Int64] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679156534"><span class="hs-identifier hs-var">strides</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-750"></span><span>                    </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef) -&gt; (OpDef -&gt; OpDef) -&gt; OpDef -&gt; OpDef
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156533"><span class="hs-identifier hs-var">dataFormat</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-751"></span><span>                </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679156532"><span class="hs-identifier hs-var">padding</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156538"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156531"><span class="hs-identifier hs-var">output</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156537"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-752"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-753"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-754"></span><span>    </span><span class="annot"><a href="#local-6989586621679156531"><span class="hs-identifier hs-type">output</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-755"></span><span>    </span><span id="local-6989586621679156531"><span class="annot"><span class="annottext">output :: Tensor Build a
</span><a href="#local-6989586621679156531"><span class="hs-identifier hs-var hs-var">output</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="annot"><span class="annottext">(Output -&gt; Tensor Build a) -&gt; Output -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">OutputIx -&gt; NodeName -&gt; Output
</span><span class="hs-identifier hs-var">Output</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef -&gt; NodeName
</span><a href="TensorFlow.Gradient.html#nodeDefName"><span class="hs-identifier hs-var">nodeDefName</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156539"><span class="hs-identifier hs-var">nodeDef</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-756"></span><span>    </span><span id="local-6989586621679156535"><span class="annot"><span class="annottext">ksize :: [Int64]
</span><a href="#local-6989586621679156535"><span class="hs-identifier hs-var hs-var">ksize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; [Int64]
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156539"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;ksize&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">]</span><span>
</span><span id="line-757"></span><span>    </span><span id="local-6989586621679156534"><span class="annot"><span class="annottext">strides :: [Int64]
</span><a href="#local-6989586621679156534"><span class="hs-identifier hs-var hs-var">strides</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; [Int64]
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156539"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;strides&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">]</span><span>
</span><span id="line-758"></span><span>    </span><span id="local-6989586621679156532"><span class="annot"><span class="annottext">padding :: ByteString
</span><a href="#local-6989586621679156532"><span class="hs-identifier hs-var hs-var">padding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156539"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;padding&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-759"></span><span>    </span><span id="local-6989586621679156533"><span class="annot"><span class="annottext">dataFormat :: ByteString
</span><a href="#local-6989586621679156533"><span class="hs-identifier hs-var hs-var">dataFormat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156539"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;data_format&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span>
</span><span id="line-760"></span><span>
</span><span id="line-761"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Reshape&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156530"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156530"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156529"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156529"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156529"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build a)
-&gt; Tensor Build Int32 -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156530"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-762"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;ExpandDims&quot;</span><span> </span><span id="local-6989586621679156528"><span class="annot"><span class="annottext">n :: NodeDef
</span><a href="#local-6989586621679156528"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679156527"><span class="annot"><span class="annottext">xs :: [Output]
</span><a href="#local-6989586621679156527"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Any
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Tensor Build Any
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679156526"><span class="annot"><span class="annottext">dzs :: [Tensor Value a]
</span><a href="#local-6989586621679156526"><span class="hs-identifier hs-var">dzs</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Text -&gt; GradientFunc a
forall a. GradientCompatible a =&gt; Text -&gt; GradientFunc a
</span><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;Reshape&quot;</span></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156528"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156527"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156526"><span class="hs-identifier hs-var">dzs</span></a></span><span>
</span><span id="line-763"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Squeeze&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156525"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156525"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156524"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156524"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156524"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">(Tensor Build Int32 -&gt; Tensor Build a)
-&gt; Tensor Build Int32 -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156525"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-764"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Pad&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Float
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156523"><span class="annot"><span class="annottext">Tensor Build Float
</span><a href="#local-6989586621679156523"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156522"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156522"><span class="hs-identifier hs-var">padPattern</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156521"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156521"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-765"></span><span>  </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t index.
(TensorType t, OneOf '[Int32, Int64] index) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 index -&gt; Tensor v'3 index -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.slice</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156521"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156520"><span class="hs-identifier hs-var">gradientSliceBegin</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156519"><span class="hs-identifier hs-var">gradientSliceSize</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-766"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-767"></span><span>    </span><span id="local-6989586621679156518"><span class="annot"><span class="annottext">v1 :: Tensor Build Int32
</span><a href="#local-6989586621679156518"><span class="hs-identifier hs-var hs-var">v1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">]</span><span>
</span><span id="line-768"></span><span>     </span><span class="hs-comment">-- For some reason rankx' has an empty shape</span><span>
</span><span id="line-769"></span><span>    </span><span id="local-6989586621679156517"><span class="annot"><span class="annottext">rankx' :: Tensor Build Int32
</span><a href="#local-6989586621679156517"><span class="hs-identifier hs-var hs-var">rankx'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Float -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build Int32
</span><span class="hs-identifier hs-var">CoreOps.rank</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Float
</span><a href="#local-6989586621679156523"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span class="hs-special">)</span><span>
</span><span id="line-770"></span><span>    </span><span id="local-6989586621679156516"><span class="annot"><span class="annottext">rankx :: Tensor Build Int32
</span><a href="#local-6989586621679156516"><span class="hs-identifier hs-var hs-var">rankx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156517"><span class="hs-identifier hs-var">rankx'</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156518"><span class="hs-identifier hs-var">v1</span></a></span><span>
</span><span id="line-771"></span><span>    </span><span class="hs-comment">-- Size of column that is sliced from pad pattern</span><span>
</span><span id="line-772"></span><span>    </span><span id="local-6989586621679156515"><span class="annot"><span class="annottext">padPatternSliceSize :: Tensor Build Int32
</span><a href="#local-6989586621679156515"><span class="hs-identifier hs-var hs-var">padPatternSliceSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; [Tensor Build Int32] -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Int32 -&gt; [Tensor v'2 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.concat</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156516"><span class="hs-identifier hs-var">rankx</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156518"><span class="hs-identifier hs-var">v1</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-773"></span><span>    </span><span id="local-6989586621679156514"><span class="annot"><span class="annottext">padPatternSliceBegin :: Tensor Build Int32
</span><a href="#local-6989586621679156514"><span class="hs-identifier hs-var hs-var">padPatternSliceBegin</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-number">0</span></span><span class="hs-special">]</span><span>
</span><span id="line-774"></span><span>    </span><span id="local-6989586621679156513"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156513"><span class="hs-identifier hs-var">padPatternSliced</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t index.
(TensorType t, OneOf '[Int32, Int64] index) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 index -&gt; Tensor v'3 index -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.slice</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156522"><span class="hs-identifier hs-var">padPattern</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156514"><span class="hs-identifier hs-var">padPatternSliceBegin</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156515"><span class="hs-identifier hs-var">padPatternSliceSize</span></a></span><span>
</span><span id="line-775"></span><span>    </span><span class="hs-comment">-- The slice of the pad pattern has the same rank as the pad pattern itself</span><span>
</span><span id="line-776"></span><span>    </span><span id="local-6989586621679156520"><span class="annot"><span class="annottext">gradientSliceBegin :: Tensor Build Int32
</span><a href="#local-6989586621679156520"><span class="hs-identifier hs-var hs-var">gradientSliceBegin</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156513"><span class="hs-identifier hs-var">padPatternSliced</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156516"><span class="hs-identifier hs-var">rankx</span></a></span><span>
</span><span id="line-777"></span><span>    </span><span id="local-6989586621679156519"><span class="annot"><span class="annottext">gradientSliceSize :: Tensor Build Int32
</span><a href="#local-6989586621679156519"><span class="hs-identifier hs-var hs-var">gradientSliceSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Float -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Float
</span><a href="#local-6989586621679156523"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span class="hs-special">)</span><span>
</span><span id="line-778"></span><span>
</span><span id="line-779"></span><span class="hs-comment">-- Gradient for Slice</span><span>
</span><span id="line-780"></span><span class="hs-comment">-- Create an Nx2 padding where N is the rank of (grad of) Slice and the first</span><span>
</span><span id="line-781"></span><span class="hs-comment">-- column represents how many zeros are to be prepended for each dimension, and the second</span><span>
</span><span id="line-782"></span><span class="hs-comment">-- column indicates how many zeros are appended.</span><span>
</span><span id="line-783"></span><span class="hs-comment">-- The number of zeros to prepend is the shape of the beginvec.</span><span>
</span><span id="line-784"></span><span class="hs-comment">-- The number of zeros to append is the shape of the inputvec</span><span>
</span><span id="line-785"></span><span class="hs-comment">-- elementwise-subtracted by both the beginvec and sizevec.</span><span>
</span><span id="line-786"></span><span class="hs-comment">-- Some more reshaping is needed to assemble this tensor with the</span><span>
</span><span id="line-787"></span><span class="hs-comment">-- right dimensions.</span><span>
</span><span id="line-788"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Slice&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Float
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156512"><span class="annot"><span class="annottext">Tensor Build Float
</span><a href="#local-6989586621679156512"><span class="hs-identifier hs-var">inputvec</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156511"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156511"><span class="hs-identifier hs-var">beginvec</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156510"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156510"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-789"></span><span>   </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.pad</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156510"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156508"><span class="hs-identifier hs-var">paddings</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-790"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-791"></span><span>    </span><span id="local-6989586621679156507"><span class="annot"><span class="annottext">v1 :: Tensor Build Int32
</span><a href="#local-6989586621679156507"><span class="hs-identifier hs-var hs-var">v1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">]</span><span>
</span><span id="line-792"></span><span>    </span><span id="local-6989586621679156506"><span class="annot"><span class="annottext">inputRank' :: Tensor Build Int32
</span><a href="#local-6989586621679156506"><span class="hs-identifier hs-var hs-var">inputRank'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Float -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build Int32
</span><span class="hs-identifier hs-var">CoreOps.rank</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Float
</span><a href="#local-6989586621679156512"><span class="hs-identifier hs-var">inputvec</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span class="hs-special">)</span><span>
</span><span id="line-793"></span><span>    </span><span class="hs-comment">-- For some reason inputRank' has an empty shape</span><span>
</span><span id="line-794"></span><span>    </span><span id="local-6989586621679156505"><span class="annot"><span class="annottext">inputRank :: Tensor Build Int32
</span><a href="#local-6989586621679156505"><span class="hs-identifier hs-var hs-var">inputRank</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156506"><span class="hs-identifier hs-var">inputRank'</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156507"><span class="hs-identifier hs-var">v1</span></a></span><span>
</span><span id="line-795"></span><span>    </span><span id="local-6989586621679156504"><span class="annot"><span class="annottext">padShape :: Tensor Build Int32
</span><a href="#local-6989586621679156504"><span class="hs-identifier hs-var hs-var">padShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; [Tensor Build Int32] -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Int32 -&gt; [Tensor v'2 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.concat</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156505"><span class="hs-identifier hs-var">inputRank</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156507"><span class="hs-identifier hs-var">v1</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-796"></span><span>    </span><span id="local-6989586621679156503"><span class="annot"><span class="annottext">beforePad :: Tensor Build Int32
</span><a href="#local-6989586621679156503"><span class="hs-identifier hs-var hs-var">beforePad</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156511"><span class="hs-identifier hs-var">beginvec</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156504"><span class="hs-identifier hs-var">padShape</span></a></span><span>
</span><span id="line-797"></span><span>    </span><span id="local-6989586621679156502"><span class="annot"><span class="annottext">afterPad :: Tensor Build Int32
</span><a href="#local-6989586621679156502"><span class="hs-identifier hs-var hs-var">afterPad</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Float -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Float
</span><a href="#local-6989586621679156512"><span class="hs-identifier hs-var">inputvec</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-glyph hs-var">-</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156510"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-glyph hs-var">-</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156511"><span class="hs-identifier hs-var">beginvec</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156504"><span class="hs-identifier hs-var">padShape</span></a></span><span>
</span><span id="line-798"></span><span>    </span><span id="local-6989586621679156508"><span class="annot"><span class="annottext">paddings :: Tensor Build Int32
</span><a href="#local-6989586621679156508"><span class="hs-identifier hs-var hs-var">paddings</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; [Tensor Build Int32] -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Int32 -&gt; [Tensor v'2 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.concat</span></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156503"><span class="hs-identifier hs-var">beforePad</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156502"><span class="hs-identifier hs-var">afterPad</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-799"></span><span>
</span><span id="line-800"></span><span class="hs-comment">-- TODO: This could be either Int32 or Int64.</span><span>
</span><span id="line-801"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;BatchToSpaceND&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">@</span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156501"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156501"><span class="hs-identifier hs-var">blockShape</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">@</span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156500"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156500"><span class="hs-identifier hs-var">crops</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156499"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156499"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-802"></span><span>  </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t
       tblock_shape tpaddings.
(TensorType t, OneOf '[Int32, Int64] tblock_shape,
 OneOf '[Int32, Int64] tpaddings) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 tblock_shape
-&gt; Tensor v'3 tpaddings
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.spaceToBatchND</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156499"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156501"><span class="hs-identifier hs-var">blockShape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156500"><span class="hs-identifier hs-var">crops</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-803"></span><span>
</span><span id="line-804"></span><span class="hs-comment">-- TODO: This could be either Int32 or Int64.</span><span>
</span><span id="line-805"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;SpaceToBatchND&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">@</span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156497"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156497"><span class="hs-identifier hs-var">blockShape</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">@</span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156496"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156496"><span class="hs-identifier hs-var">paddings</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156495"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156495"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-806"></span><span>  </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t
       tblock_shape tpaddings.
(TensorType t, OneOf '[Int32, Int64] tblock_shape,
 OneOf '[Int32, Int64] tpaddings) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 tblock_shape
-&gt; Tensor v'3 tpaddings
-&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.batchToSpaceND</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156495"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156497"><span class="hs-identifier hs-var">blockShape</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156496"><span class="hs-identifier hs-var">paddings</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-807"></span><span>
</span><span id="line-808"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;OneHot&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-809"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;TruncatedNormal&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-810"></span><span>
</span><span id="line-811"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;RefIdentity&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156493"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156493"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v :: * -&gt; *) a.
TensorKind v =&gt;
Tensor v a -&gt; Tensor Build a
</span><span class="hs-identifier hs-var">expr</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156493"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-812"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Cast&quot;</span><span> </span><span id="local-6989586621679156492"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156492"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156491"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156491"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156490"><span class="hs-identifier hs-var">reverseCast</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-813"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-814"></span><span>    </span><span class="hs-comment">-- TODO(gnezdo): too permissive, python only allows float types as src_type.</span><span>
</span><span id="line-815"></span><span>    </span><span id="local-6989586621679156490"><span class="annot"><span class="annottext">reverseCast :: Tensor Build a
</span><a href="#local-6989586621679156490"><span class="hs-identifier hs-var hs-var">reverseCast</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-816"></span><span>        </span><span class="annot"><span class="annottext">[Int64] -&gt; Build OpDef -&gt; Tensor Build a
forall a. PureResult a =&gt; [Int64] -&gt; Build OpDef -&gt; a
</span><span class="hs-identifier hs-var">pureOp</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">(Build OpDef -&gt; Tensor Build a) -&gt; Build OpDef -&gt; Tensor Build a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">OpDef -&gt; Build OpDef
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><span class="hs-identifier hs-var">pure</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OpType -&gt; OpDef
</span><span class="hs-identifier hs-var">opDef</span></span><span> </span><span class="annot"><span class="hs-string">&quot;Cast&quot;</span></span><span>
</span><span id="line-817"></span><span>                 </span><span class="annot"><span class="annottext">OpDef -&gt; (OpDef -&gt; OpDef) -&gt; OpDef
forall s t. s -&gt; (s -&gt; t) -&gt; t
</span><span class="hs-operator hs-var">&amp;</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;DstT&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156492"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;SrcT&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span class="hs-special">)</span><span>
</span><span id="line-818"></span><span>                 </span><span class="annot"><span class="annottext">OpDef -&gt; (OpDef -&gt; OpDef) -&gt; OpDef
forall s t. s -&gt; (s -&gt; t) -&gt; t
</span><span class="hs-operator hs-var">&amp;</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef ByteString
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;SrcT&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef ByteString)
-&gt; ByteString -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; ByteString
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156492"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;DstT&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ByteString</span></span><span class="hs-special">)</span><span>
</span><span id="line-819"></span><span>                 </span><span class="annot"><span class="annottext">OpDef -&gt; (OpDef -&gt; OpDef) -&gt; OpDef
forall s t. s -&gt; (s -&gt; t) -&gt; t
</span><span class="hs-operator hs-var">&amp;</span></span><span> </span><span class="annot"><span class="annottext">Lens' OpDef [Output]
forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Output]
</span><span class="hs-identifier hs-var">opInputs</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef [Output])
-&gt; [Output] -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Output
forall (t :: * -&gt; *) a. Rendered t =&gt; t a -&gt; Output
</span><span class="hs-identifier hs-var">renderedOutput</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156491"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-820"></span><span>
</span><span id="line-821"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;DynamicStitch&quot;</span><span> </span><span id="local-6989586621679156488"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156488"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span id="local-6989586621679156487"><span class="annot"><span class="annottext">inputs :: [Output]
</span><a href="#local-6989586621679156487"><span class="hs-identifier hs-var">inputs</span></a></span></span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156486"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156486"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-822"></span><span>    </span><span class="annot"><span class="annottext">Node -&gt; Maybe (Tensor Build a) -&gt; [Maybe (Tensor Build a)]
forall a. Node -&gt; a -&gt; [a]
</span><span class="hs-identifier hs-var">replicate</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156484"><span class="hs-identifier hs-var">halfLen</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span> </span><span class="annot"><span class="annottext">[Maybe (Tensor Build a)]
-&gt; [Maybe (Tensor Build a)] -&gt; [Maybe (Tensor Build a)]
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">[Maybe (Tensor Build a)]
</span><a href="#local-6989586621679156483"><span class="hs-identifier hs-var">valuesGrads</span></a></span><span>
</span><span id="line-823"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-824"></span><span>    </span><span id="local-6989586621679156484"><span class="annot"><span class="annottext">halfLen :: Node
</span><a href="#local-6989586621679156484"><span class="hs-identifier hs-var hs-var">halfLen</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-825"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679156482"><span class="annot"><span class="annottext">len :: Node
</span><a href="#local-6989586621679156482"><span class="hs-identifier hs-var hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Output] -&gt; Node
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Node
</span><span class="hs-identifier hs-var">length</span></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156487"><span class="hs-identifier hs-var">inputs</span></a></span><span>
</span><span id="line-826"></span><span>            </span><span id="local-6989586621679156481"><span class="annot"><span class="annottext">half :: Node
</span><a href="#local-6989586621679156481"><span class="hs-identifier hs-var hs-var">half</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156482"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Node -&gt; Node -&gt; Node
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">`div`</span></span><span> </span><span class="annot"><span class="hs-number">2</span></span><span>
</span><span id="line-827"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Node -&gt; Node -&gt; Node
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">*</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156481"><span class="hs-identifier hs-var">half</span></a></span><span> </span><span class="annot"><span class="annottext">Node -&gt; Node -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156482"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-828"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156481"><span class="hs-identifier hs-var">half</span></a></span><span>
</span><span id="line-829"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; Node
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-string">&quot;Uneven input size &quot;</span></span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; [Char] -&gt; [Char]
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">(Node, [Char]) -&gt; [Char]
forall a. Show a =&gt; a -&gt; [Char]
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156482"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; [Char]
forall msg. Message msg =&gt; msg -&gt; [Char]
</span><span class="hs-identifier hs-var">showMessage</span></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156488"><span class="hs-identifier hs-var">nodeDef</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-830"></span><span>    </span><span id="local-6989586621679156483"><span class="annot"><span class="annottext">valuesGrads :: [Maybe (Tensor Build a)]
</span><a href="#local-6989586621679156483"><span class="hs-identifier hs-var hs-var">valuesGrads</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.gather</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156486"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="annot"><span class="annottext">Output
</span><a href="#local-6989586621679156478"><span class="hs-identifier hs-var">idx</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span>
</span><span id="line-831"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621679156478"><span class="annot"><span class="annottext">Output
</span><a href="#local-6989586621679156478"><span class="hs-identifier hs-var">idx</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Node -&gt; [Output] -&gt; [Output]
forall a. Node -&gt; [a] -&gt; [a]
</span><span class="hs-identifier hs-var">take</span></span><span> </span><span class="annot"><span class="annottext">Node
</span><a href="#local-6989586621679156484"><span class="hs-identifier hs-var">halfLen</span></a></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156487"><span class="hs-identifier hs-var">inputs</span></a></span><span>
</span><span id="line-832"></span><span>                  </span><span class="hs-special">]</span><span>
</span><span id="line-833"></span><span>
</span><span id="line-834"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;DynamicPartition&quot;</span><span> </span><span id="local-6989586621679156476"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156476"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156475"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156475"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156474"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156474"><span class="hs-identifier hs-var">indices</span></a></span></span><span class="hs-special">]</span><span> </span><span id="local-6989586621679156473"><span class="annot"><span class="annottext">dz :: [Tensor Value a]
</span><a href="#local-6989586621679156473"><span class="hs-identifier hs-var">dz</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-835"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156472"><span class="hs-identifier hs-var">reconstructed</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-836"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-837"></span><span>    </span><span id="local-6989586621679156472"><span class="annot"><span class="annottext">reconstructed :: Tensor Build a
</span><a href="#local-6989586621679156472"><span class="hs-identifier hs-var hs-var">reconstructed</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156471"><span class="hs-identifier hs-var">stitched</span></a></span><span>
</span><span id="line-838"></span><span>                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t out_type.
(TensorType t, OneOf '[Int32, Int64] out_type) =&gt;
Tensor v'1 t -&gt; Tensor Build out_type
</span><span class="hs-identifier hs-var">CoreOps.shape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156475"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span>
</span><span id="line-839"></span><span>    </span><span id="local-6989586621679156471"><span class="annot"><span class="annottext">stitched :: Tensor Build a
</span><a href="#local-6989586621679156471"><span class="hs-identifier hs-var hs-var">stitched</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Tensor Build Int32] -&gt; [Tensor Value a] -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
TensorType t =&gt;
[Tensor v'1 Int32] -&gt; [Tensor v'2 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.dynamicStitch</span></span><span> </span><span class="annot"><span class="annottext">[Tensor Build Int32]
</span><a href="#local-6989586621679156468"><span class="hs-identifier hs-var">partitionedIndices</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156473"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-840"></span><span>    </span><span id="local-6989586621679156468"><span class="annot"><span class="annottext">partitionedIndices :: [Tensor Build Int32]
</span><a href="#local-6989586621679156468"><span class="hs-identifier hs-var hs-var">partitionedIndices</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int64
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; [Tensor Build Int32]
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
TensorType t =&gt;
Int64 -&gt; Tensor v'1 t -&gt; Tensor v'2 Int32 -&gt; [Tensor Build t]
</span><span class="hs-identifier hs-var">CoreOps.dynamicPartition</span></span><span> </span><span class="annot"><span class="annottext">Int64
</span><a href="#local-6989586621679156466"><span class="hs-identifier hs-var">np</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156465"><span class="hs-identifier hs-var">originalIndices</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156474"><span class="hs-identifier hs-var">indices</span></a></span><span>
</span><span id="line-841"></span><span>    </span><span id="local-6989586621679156466"><span class="annot"><span class="annottext">np :: Int64
</span><a href="#local-6989586621679156466"><span class="hs-identifier hs-var hs-var">np</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Int64
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156476"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;num_partitions&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span>
</span><span id="line-842"></span><span>    </span><span id="local-6989586621679156465"><span class="annot"><span class="annottext">originalIndices :: Tensor Build Int32
</span><a href="#local-6989586621679156465"><span class="hs-identifier hs-var hs-var">originalIndices</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-843"></span><span>        </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) tidx.
OneOf '[Int32, Int64, Word16, Double, Float] tidx =&gt;
Tensor v'1 tidx
-&gt; Tensor v'2 tidx -&gt; Tensor v'3 tidx -&gt; Tensor Build tidx
</span><span class="hs-identifier hs-var">CoreOps.range</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t out_type.
(TensorType t, OneOf '[Int32, Int64] out_type) =&gt;
Tensor v'1 t -&gt; Tensor Build out_type
</span><span class="hs-identifier hs-var">CoreOps.size</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156474"><span class="hs-identifier hs-var">indices</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156462"><span class="hs-identifier hs-var">prefixShape</span></a></span><span>
</span><span id="line-844"></span><span>    </span><span id="local-6989586621679156462"><span class="annot"><span class="annottext">prefixShape :: Tensor Build Int32
</span><a href="#local-6989586621679156462"><span class="hs-identifier hs-var hs-var">prefixShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="#local-6989586621679156461"><span class="hs-identifier hs-var">shapeInt32</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156474"><span class="hs-identifier hs-var">indices</span></a></span><span>
</span><span id="line-845"></span><span>    </span><span id="local-6989586621679156461"><span class="annot"><span class="annottext">shapeInt32 :: Tensor v'1 t -&gt; Tensor Build Int32
</span><a href="#local-6989586621679156461"><span class="hs-identifier hs-var hs-var">shapeInt32</span></a></span></span><span> </span><span id="local-6989586621679156460"><span class="annot"><span class="annottext">t :: Tensor v'1 t
</span><a href="#local-6989586621679156460"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor v'1 t -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t out_type.
(TensorType t, OneOf '[Int32, Int64] out_type) =&gt;
Tensor v'1 t -&gt; Tensor Build out_type
</span><span class="hs-identifier hs-var">CoreOps.shape</span></span><span> </span><span class="annot"><span class="annottext">Tensor v'1 t
</span><a href="#local-6989586621679156460"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span>
</span><span id="line-846"></span><span>
</span><span id="line-847"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Select&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Bool
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156459"><span class="annot"><span class="annottext">Tensor Build Bool
</span><a href="#local-6989586621679156459"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156458"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156458"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156457"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156457"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-848"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-849"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
-&gt; Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Bool -&gt; Tensor v'2 t -&gt; Tensor v'3 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.select</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
</span><a href="#local-6989586621679156459"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156457"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156456"><span class="hs-identifier hs-var">zeros</span></a></span><span>
</span><span id="line-850"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
-&gt; Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 Bool -&gt; Tensor v'2 t -&gt; Tensor v'3 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.select</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Bool
</span><a href="#local-6989586621679156459"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156456"><span class="hs-identifier hs-var">zeros</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156457"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-851"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-852"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679156456"><span class="annot"><span class="annottext">zeros :: Tensor Build a
</span><a href="#local-6989586621679156456"><span class="hs-identifier hs-var hs-var">zeros</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.zerosLike</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156458"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-853"></span><span>
</span><span id="line-854"></span><span class="hs-comment">-- TODO(gnezdo): Unlike Python, no control dependency on dz.</span><span>
</span><span id="line-855"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Log&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156455"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156455"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156454"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156454"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156454"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.inv</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156455"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-856"></span><span class="hs-comment">-- TODO(gnezdo): Reuse the output instead of doing another exp,</span><span>
</span><span id="line-857"></span><span class="hs-comment">-- though, it is probably CSE'd away anyway.</span><span>
</span><span id="line-858"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Exp&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156452"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156452"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156451"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156451"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156451"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
OneOf '[Complex Double, Complex Float, Word16, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.exp</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156452"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-859"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;SparseSegmentSum&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156449"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156449"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156448"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156448"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156447"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156447"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156446"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156446"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-860"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) t tindices
       tnumsegments.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tindices,
 OneOf '[Int32, Int64] tnumsegments) =&gt;
Tensor v'1 t
-&gt; Tensor v'2 tindices -&gt; Tensor v'3 tnumsegments -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.unsortedSegmentSum</span></span><span>
</span><span id="line-861"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.gather</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156446"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156447"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-862"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156448"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156445"><span class="hs-identifier hs-var">inputRows</span></a></span><span>
</span><span id="line-863"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-864"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-865"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-866"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679156445"><span class="annot"><span class="annottext">inputRows :: Tensor Build Int32
</span><a href="#local-6989586621679156445"><span class="hs-identifier hs-var hs-var">inputRows</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Int32 -&gt; Int32 -&gt; Tensor Build Int32
forall (v1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v1 t -&gt; Int32 -&gt; Int32 -&gt; Tensor Build t
</span><a href="TensorFlow.Gradient.html#flatSlice"><span class="hs-identifier hs-var">flatSlice</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156449"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-867"></span><span>
</span><span id="line-868"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;LabelClasses&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-869"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;LabelWeights&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-870"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Size&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-871"></span><span>
</span><span id="line-872"></span><span class="hs-comment">-- TODO (jcberentsen): Python implementation uses set_shape for</span><span>
</span><span id="line-873"></span><span class="hs-comment">-- static shape inference, which is unsupported.</span><span>
</span><span id="line-874"></span><span class="hs-comment">-- TODO: implement support for static shape inference</span><span>
</span><span id="line-875"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Tile&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156444"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156444"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Output -&gt; Tensor Build Int32
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156443"><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156443"><span class="hs-identifier hs-var">multiples</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156442"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156442"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-876"></span><span>    </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156441"><span class="hs-identifier hs-var">inputGrad</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-877"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-878"></span><span>    </span><span id="local-6989586621679156441"><span class="annot"><span class="annottext">inputGrad :: Tensor Build a
</span><a href="#local-6989586621679156441"><span class="hs-identifier hs-var hs-var">inputGrad</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156440"><span class="hs-identifier hs-var">reshapedDz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156439"><span class="hs-identifier hs-var">axes</span></a></span><span>
</span><span id="line-879"></span><span>    </span><span id="local-6989586621679156438"><span class="annot"><span class="annottext">inputShape :: Tensor Build Int32
</span><a href="#local-6989586621679156438"><span class="hs-identifier hs-var hs-var">inputShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build Int32
forall t (v :: * -&gt; *).
TensorType t =&gt;
Tensor v t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Ops.html#shape"><span class="hs-identifier hs-var">shape</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156444"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><a href="#local-6989586621679157265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-880"></span><span>    </span><span id="local-6989586621679156437"><span class="annot"><span class="annottext">packed :: Tensor Build Int32
</span><a href="#local-6989586621679156437"><span class="hs-identifier hs-var hs-var">packed</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Tensor Build Int32] -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
[Tensor v'1 t] -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.pack</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156443"><span class="hs-identifier hs-var">multiples</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156438"><span class="hs-identifier hs-var">inputShape</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-881"></span><span>    </span><span id="local-6989586621679156435"><span class="annot"><span class="annottext">perm :: Tensor Build Int32
</span><a href="#local-6989586621679156435"><span class="hs-identifier hs-var hs-var">perm</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">]</span><span>
</span><span id="line-882"></span><span>    </span><span id="local-6989586621679156434"><span class="annot"><span class="annottext">splitShape :: Tensor Build Int32
</span><a href="#local-6989586621679156434"><span class="hs-identifier hs-var hs-var">splitShape</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.transpose</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156437"><span class="hs-identifier hs-var">packed</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156435"><span class="hs-identifier hs-var">perm</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#allDimensions"><span class="hs-identifier hs-var">allDimensions</span></a></span><span>
</span><span id="line-883"></span><span>    </span><span id="local-6989586621679156439"><span class="annot"><span class="annottext">axes :: Tensor Build Int32
</span><a href="#local-6989586621679156439"><span class="hs-identifier hs-var hs-var">axes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) tidx.
OneOf '[Int32, Int64, Word16, Double, Float] tidx =&gt;
Tensor v'1 tidx
-&gt; Tensor v'2 tidx -&gt; Tensor v'3 tidx -&gt; Tensor Build tidx
</span><span class="hs-identifier hs-var">CoreOps.range</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t out_type.
(TensorType t, OneOf '[Int32, Int64] out_type) =&gt;
Tensor v'1 t -&gt; Tensor Build out_type
</span><span class="hs-identifier hs-var">CoreOps.size</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156434"><span class="hs-identifier hs-var">splitShape</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-number">2</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">)</span><span>
</span><span id="line-884"></span><span>    </span><span id="local-6989586621679156440"><span class="annot"><span class="annottext">reshapedDz :: Tensor Build a
</span><a href="#local-6989586621679156440"><span class="hs-identifier hs-var hs-var">reshapedDz</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tshape.
(TensorType t, OneOf '[Int32, Int64] tshape) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tshape -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.reshape</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156442"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156434"><span class="hs-identifier hs-var">splitShape</span></a></span><span>
</span><span id="line-885"></span><span>
</span><span id="line-886"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;ResizeBilinear&quot;</span><span> </span><span id="local-6989586621679156433"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156433"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156432"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156432"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156431"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156431"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-887"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(OpDef -&gt; OpDef)
-&gt; Tensor Build Float -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Word16, Double, Float] t =&gt;
(OpDef -&gt; OpDef)
-&gt; Tensor v'1 Float -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.resizeBilinearGrad'</span></span><span>
</span><span id="line-888"></span><span>               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text -&gt; Lens' OpDef Bool
forall a. Attribute a =&gt; Text -&gt; Lens' OpDef a
</span><span class="hs-identifier hs-var">opAttr</span></span><span> </span><span class="annot"><span class="hs-string">&quot;align_corners&quot;</span></span><span> </span><span class="annot"><span class="annottext">(forall (f :: * -&gt; *). Identical f =&gt; LensLike' f OpDef Bool)
-&gt; Bool -&gt; OpDef -&gt; OpDef
forall s t a b. Setter s t a b -&gt; b -&gt; s -&gt; t
</span><span class="hs-operator hs-var">.~</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679156429"><span class="hs-identifier hs-var">align</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-889"></span><span>               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Float
forall (v'1 :: * -&gt; *) srcT dstT.
(TensorType srcT, TensorType dstT) =&gt;
Tensor v'1 srcT -&gt; Tensor Build dstT
</span><span class="hs-identifier hs-var">CoreOps.cast</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156431"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-890"></span><span>               </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156432"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-891"></span><span>
</span><span id="line-892"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span>
</span><span id="line-893"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-894"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-895"></span><span>    </span><span id="local-6989586621679156429"><span class="annot"><span class="annottext">align :: Bool
</span><a href="#local-6989586621679156429"><span class="hs-identifier hs-var hs-var">align</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Bool
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156433"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;align_corners&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-896"></span><span>
</span><span id="line-897"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;ZerosLike&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-898"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Fill&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156428"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156428"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32 -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t tidx.
(OneOf
   '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
     Word32, Word64, Word8, Double, Float]
   t,
 OneOf '[Int32, Int64] tidx) =&gt;
Tensor v'1 t -&gt; Tensor v'2 tidx -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">sum</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156428"><span class="hs-identifier hs-var">dz</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
</span><a href="#local-6989586621679156427"><span class="hs-identifier hs-var">rx</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-899"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-900"></span><span>    </span><span id="local-6989586621679156427"><span class="annot"><span class="annottext">rx :: Tensor Build Int32
</span><a href="#local-6989586621679156427"><span class="hs-identifier hs-var hs-var">rx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#rangeOfRank"><span class="hs-identifier hs-var">rangeOfRank</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156428"><span class="hs-identifier hs-var">dz</span></a></span><span>
</span><span id="line-901"></span><span>
</span><span id="line-902"></span><span class="hs-comment">-- Treat read ops as an identity function on the variable. This allows us to</span><span>
</span><span id="line-903"></span><span class="hs-comment">-- take gradients w.r.t. to the variable handle instead of the result of a read</span><span>
</span><span id="line-904"></span><span class="hs-comment">-- op. If a variable is read multiple times, the gradients will propagate back</span><span>
</span><span id="line-905"></span><span class="hs-comment">-- through each read.</span><span>
</span><span id="line-906"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;ReadVariableOp&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156426"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156426"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a -&gt; Tensor Build a
forall (v :: * -&gt; *) a.
TensorKind v =&gt;
Tensor v a -&gt; Tensor Build a
</span><span class="hs-identifier hs-var">expr</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156426"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-907"></span><span>
</span><span id="line-908"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Const&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-909"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;StopGradient&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (Tensor Build a)
forall a. Maybe a
</span><span class="hs-identifier hs-var">Nothing</span></span><span class="hs-special">]</span><span>
</span><span id="line-910"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;VarHandleOp&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-911"></span><span>
</span><span id="line-912"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span class="hs-string">&quot;Sqrt&quot;</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Output -&gt; Tensor Build a
forall a. Output -&gt; Tensor Build a
</span><a href="TensorFlow.Gradient.html#toT"><span class="hs-identifier hs-var">toT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span id="local-6989586621679156425"><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156425"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span id="local-6989586621679156424"><span class="annot"><span class="annottext">dz :: Tensor Value a
</span><a href="#local-6989586621679156424"><span class="hs-identifier hs-var">dz</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Tensor Build a -&gt; Maybe (Tensor Build a)
forall a. a -&gt; Maybe a
</span><span class="hs-identifier hs-var">Just</span></span><span> </span><span class="annot"><span class="annottext">(Tensor Build a -&gt; Maybe (Tensor Build a))
-&gt; Tensor Build a -&gt; Maybe (Tensor Build a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156423"><span class="hs-identifier hs-var">sq'</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Value a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Value a
</span><a href="#local-6989586621679156424"><span class="hs-identifier hs-var">dz</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-913"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-914"></span><span>    </span><span id="local-6989586621679156423"><span class="annot"><span class="annottext">sq' :: Tensor Build a
</span><a href="#local-6989586621679156423"><span class="hs-identifier hs-var hs-var">sq'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Tensor Build a
forall a. TensorType a =&gt; a -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#scalar"><span class="hs-identifier hs-var">scalar</span></a></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.div`</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Tensor Build a
forall a. TensorType a =&gt; a -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#scalar"><span class="hs-identifier hs-var">scalar</span></a></span><span> </span><span class="annot"><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.mul`</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a -&gt; Tensor Build a
forall (v'1 :: * -&gt; *) t.
OneOf '[Complex Double, Complex Float, Word16, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.sqrt</span></span><span> </span><span class="annot"><span class="annottext">Tensor Build a
</span><a href="#local-6989586621679156425"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-915"></span><span>
</span><span id="line-916"></span><span class="annot"><a href="TensorFlow.Gradient.html#opGrad"><span class="hs-identifier hs-var">opGrad</span></a></span><span> </span><span id="local-6989586621679156421"><span class="annot"><span class="annottext">n :: Text
</span><a href="#local-6989586621679156421"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679156420"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156420"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span id="local-6989586621679156419"><span class="annot"><span class="annottext">ins :: [Output]
</span><a href="#local-6989586621679156419"><span class="hs-identifier hs-var">ins</span></a></span></span><span> </span><span id="local-6989586621679156418"><span class="annot"><span class="annottext">grads :: [Tensor Value a]
</span><a href="#local-6989586621679156418"><span class="hs-identifier hs-var">grads</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-917"></span><span>    </span><span class="annot"><span class="annottext">[Char] -&gt; [Maybe (Tensor Build a)]
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="annot"><span class="annottext">([Char] -&gt; [Maybe (Tensor Build a)])
-&gt; [Char] -&gt; [Maybe (Tensor Build a)]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="hs-string">&quot;no gradient implemented for &quot;</span></span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; [Char] -&gt; [Char]
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span>
</span><span id="line-918"></span><span>            </span><span class="annot"><span class="annottext">(Text, Node, Node, [Char], [Output]) -&gt; [Char]
forall a. Show a =&gt; a -&gt; [Char]
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156421"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Output] -&gt; Node
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Node
</span><span class="hs-identifier hs-var">length</span></span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156419"><span class="hs-identifier hs-var">ins</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Tensor Value a] -&gt; Node
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Node
</span><span class="hs-identifier hs-var">length</span></span><span> </span><span class="annot"><span class="annottext">[Tensor Value a]
</span><a href="#local-6989586621679156418"><span class="hs-identifier hs-var">grads</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; [Char]
forall msg. Message msg =&gt; msg -&gt; [Char]
</span><span class="hs-identifier hs-var">showMessage</span></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156420"><span class="hs-identifier hs-var">nodeDef</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Output]
</span><a href="#local-6989586621679156419"><span class="hs-identifier hs-var">ins</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-919"></span><span>
</span><span id="line-920"></span><span class="hs-comment">-- | The number of outputs for an op type.</span><span>
</span><span id="line-921"></span><span class="annot"><a href="TensorFlow.Gradient.html#numOutputs"><span class="hs-identifier hs-type">numOutputs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">OutputIx</span></span><span>
</span><span id="line-922"></span><span id="numOutputs"><span class="annot"><span class="annottext">numOutputs :: NodeDef -&gt; OutputIx
</span><a href="TensorFlow.Gradient.html#numOutputs"><span class="hs-identifier hs-var hs-var">numOutputs</span></a></span></span><span> </span><span id="local-6989586621679156417"><span class="annot"><span class="annottext">o :: NodeDef
</span><a href="#local-6989586621679156417"><span class="hs-identifier hs-var">o</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-923"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156417"><span class="hs-identifier hs-var">o</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike Text NodeDef NodeDef Text Text -&gt; Text
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;op&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">op</span></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-924"></span><span>        </span><span class="hs-string">&quot;Abs&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-925"></span><span>        </span><span class="hs-string">&quot;Add&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-926"></span><span>        </span><span class="hs-string">&quot;AddN&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-927"></span><span>        </span><span class="hs-string">&quot;BatchToSpaceND&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-928"></span><span>        </span><span class="hs-string">&quot;BatchMatMul&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-929"></span><span>        </span><span class="hs-string">&quot;Cast&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-930"></span><span>        </span><span class="hs-string">&quot;Const&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-931"></span><span>        </span><span class="hs-string">&quot;Concat&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-932"></span><span>        </span><span class="hs-string">&quot;Conv2D&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-933"></span><span>        </span><span class="hs-string">&quot;Conv2DBackpropInput&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-934"></span><span>        </span><span class="hs-string">&quot;DepthwiseConv2dNative&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-935"></span><span>        </span><span class="hs-string">&quot;DepthwiseConv2dNativeBackpropInput&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-936"></span><span>        </span><span class="hs-string">&quot;Div&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-937"></span><span>        </span><span class="hs-string">&quot;DynamicStitch&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-938"></span><span>        </span><span class="hs-string">&quot;DynamicPartition&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-939"></span><span>            </span><span class="annot"><span class="annottext">Int64 -&gt; OutputIx
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><span class="hs-identifier hs-var">fromIntegral</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef -&gt; Text -&gt; Int64
forall a1. Attribute a1 =&gt; NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var">lookupAttr</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156417"><span class="hs-identifier hs-var">o</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;num_partitions&quot;</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">)</span><span>
</span><span id="line-940"></span><span>        </span><span class="hs-string">&quot;Exp&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-941"></span><span>        </span><span class="hs-string">&quot;ExpandDims&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-942"></span><span>        </span><span class="hs-string">&quot;Gather&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-943"></span><span>        </span><span class="hs-string">&quot;LabelClasses&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-944"></span><span>        </span><span class="hs-string">&quot;LabelWeights&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-945"></span><span>        </span><span class="hs-string">&quot;Log&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-946"></span><span>        </span><span class="hs-string">&quot;MatMul&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-947"></span><span>        </span><span class="hs-string">&quot;Max&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-948"></span><span>        </span><span class="hs-string">&quot;Maximum&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-949"></span><span>        </span><span class="hs-string">&quot;MaxPool&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-950"></span><span>        </span><span class="hs-string">&quot;Mean&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-951"></span><span>        </span><span class="hs-string">&quot;Min&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-952"></span><span>        </span><span class="hs-string">&quot;Mul&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-953"></span><span>        </span><span class="hs-string">&quot;Neg&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-954"></span><span>        </span><span class="hs-string">&quot;Pad&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-955"></span><span>        </span><span class="hs-string">&quot;Placeholder&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-956"></span><span>        </span><span class="hs-string">&quot;StopGradient&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-957"></span><span>        </span><span class="hs-string">&quot;OneHot&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-958"></span><span>        </span><span class="hs-string">&quot;ReadVariableOp&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-959"></span><span>        </span><span class="hs-string">&quot;RefIdentity&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-960"></span><span>        </span><span class="hs-string">&quot;Relu&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-961"></span><span>        </span><span class="hs-string">&quot;ReluGrad&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-962"></span><span>        </span><span class="hs-string">&quot;Reshape&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-963"></span><span>        </span><span class="hs-string">&quot;Select&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-964"></span><span>        </span><span class="hs-string">&quot;Sigmoid&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-965"></span><span>        </span><span class="hs-string">&quot;Size&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-966"></span><span>        </span><span class="hs-string">&quot;Slice&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-967"></span><span>        </span><span class="hs-string">&quot;SoftmaxCrossEntropyWithLogits&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">2</span></span><span>
</span><span id="line-968"></span><span>        </span><span class="hs-string">&quot;SpaceToBatchND&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-969"></span><span>        </span><span class="hs-string">&quot;SparseSegmentSum&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-970"></span><span>        </span><span class="hs-string">&quot;Square&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-971"></span><span>        </span><span class="hs-string">&quot;Squeeze&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-972"></span><span>        </span><span class="hs-string">&quot;Sqrt&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-973"></span><span>        </span><span class="hs-string">&quot;Sub&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-974"></span><span>        </span><span class="hs-string">&quot;Sum&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-975"></span><span>        </span><span class="hs-string">&quot;Tanh&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-976"></span><span>        </span><span class="hs-string">&quot;Tile&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-977"></span><span>        </span><span class="hs-string">&quot;ResizeBilinear&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-978"></span><span>        </span><span class="hs-string">&quot;Transpose&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-979"></span><span>        </span><span class="hs-string">&quot;TruncatedNormal&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-980"></span><span>        </span><span class="hs-string">&quot;VarHandleOp&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-981"></span><span>        </span><span class="hs-string">&quot;Variable&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-982"></span><span>        </span><span class="hs-string">&quot;ZerosLike&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-983"></span><span>        </span><span class="hs-string">&quot;Fill&quot;</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-984"></span><span>        </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; OutputIx
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="annot"><span class="annottext">([Char] -&gt; OutputIx) -&gt; [Char] -&gt; OutputIx
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="hs-string">&quot;numOutputs not implemented for &quot;</span></span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; [Char] -&gt; [Char]
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; [Char]
forall a. Show a =&gt; a -&gt; [Char]
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156417"><span class="hs-identifier hs-var">o</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike Text NodeDef NodeDef Text Text -&gt; Text
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">FoldLike Text NodeDef NodeDef Text Text
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;op&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">op</span></span><span class="hs-special">)</span><span>
</span><span id="line-985"></span><span>
</span><span id="line-986"></span><span class="hs-comment">-- Divides `x / y` assuming `x, y &gt;= 0`, treating `0 / 0 = 0`</span><span>
</span><span id="line-987"></span><span id="local-6989586621679157094"><span id="local-6989586621679157095"><span class="annot"><a href="TensorFlow.Gradient.html#safeShapeDiv"><span class="hs-identifier hs-type">safeShapeDiv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679157095"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679157094"><span class="hs-identifier hs-type">v2</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span></span></span><span>
</span><span id="line-988"></span><span id="safeShapeDiv"><span class="annot"><span class="annottext">safeShapeDiv :: Tensor v1 Int32 -&gt; Tensor v2 Int32 -&gt; Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#safeShapeDiv"><span class="hs-identifier hs-var hs-var">safeShapeDiv</span></a></span></span><span> </span><span id="local-6989586621679156416"><span class="annot"><span class="annottext">x :: Tensor v1 Int32
</span><a href="#local-6989586621679156416"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679156415"><span class="annot"><span class="annottext">y :: Tensor v2 Int32
</span><a href="#local-6989586621679156415"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor v1 Int32
</span><a href="#local-6989586621679156416"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor v1 Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf
  '[Complex Double, Complex Float, Int16, Int32, Int64, Int8, Word16,
    Word8, Double, Float]
  t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-operator hs-var">`CoreOps.div`</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor v2 Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) t.
OneOf '[Int16, Int32, Int64, Word16, Word8, Double, Float] t =&gt;
Tensor v'1 t -&gt; Tensor v'2 t -&gt; Tensor Build t
</span><span class="hs-identifier hs-var">CoreOps.maximum</span></span><span> </span><span class="annot"><span class="annottext">Tensor v2 Int32
</span><a href="#local-6989586621679156415"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-989"></span><span>
</span><span id="line-990"></span><span class="annot"><a href="TensorFlow.Gradient.html#allDimensions"><span class="hs-identifier hs-type">allDimensions</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span>
</span><span id="line-991"></span><span id="allDimensions"><span class="annot"><span class="annottext">allDimensions :: Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#allDimensions"><span class="hs-identifier hs-var hs-var">allDimensions</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int32] -&gt; Tensor Build Int32
forall a. TensorType a =&gt; [a] -&gt; Tensor Build a
</span><a href="TensorFlow.Ops.html#vector"><span class="hs-identifier hs-var">vector</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-glyph">-</span><span class="annot"><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span class="hs-special">]</span><span>
</span><span id="line-992"></span><span>
</span><span id="line-993"></span><span class="annot"><a href="TensorFlow.Gradient.html#rangeOfRank"><span class="hs-identifier hs-type">rangeOfRank</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679156413"><span class="annot"><a href="#local-6989586621679156413"><span class="hs-identifier hs-type">v1</span></a></span></span><span> </span><span id="local-6989586621679156412"><span class="annot"><a href="#local-6989586621679156412"><span class="hs-identifier hs-type">t</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><span class="hs-identifier hs-type">TensorType</span></span><span> </span><span class="annot"><a href="#local-6989586621679156412"><span class="hs-identifier hs-type">t</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><a href="#local-6989586621679156413"><span class="hs-identifier hs-type">v1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679156412"><span class="hs-identifier hs-type">t</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Tensor</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Build</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int32</span></span><span>
</span><span id="line-994"></span><span id="rangeOfRank"><span class="annot"><span class="annottext">rangeOfRank :: Tensor v1 t -&gt; Tensor Build Int32
</span><a href="TensorFlow.Gradient.html#rangeOfRank"><span class="hs-identifier hs-var hs-var">rangeOfRank</span></a></span></span><span> </span><span id="local-6989586621679156411"><span class="annot"><span class="annottext">x :: Tensor v1 t
</span><a href="#local-6989586621679156411"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tensor Build Int32
-&gt; Tensor Build Int32 -&gt; Tensor Build Int32 -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) (v'2 :: * -&gt; *) (v'3 :: * -&gt; *) tidx.
OneOf '[Int32, Int64, Word16, Double, Float] tidx =&gt;
Tensor v'1 tidx
-&gt; Tensor v'2 tidx -&gt; Tensor v'3 tidx -&gt; Tensor Build tidx
</span><span class="hs-identifier hs-var">CoreOps.range</span></span><span> </span><span class="annot"><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor v1 t -&gt; Tensor Build Int32
forall (v'1 :: * -&gt; *) t.
TensorType t =&gt;
Tensor v'1 t -&gt; Tensor Build Int32
</span><span class="hs-identifier hs-var">CoreOps.rank</span></span><span> </span><span class="annot"><span class="annottext">Tensor v1 t
</span><a href="#local-6989586621679156411"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-number">1</span></span><span>
</span><span id="line-995"></span><span>
</span><span id="line-996"></span><span id="local-6989586621679157085"><span class="annot"><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-type">lookupAttr</span></a></span><span> </span><span class="hs-glyph">::</span><span>  </span><span class="annot"><span class="hs-identifier hs-type">Attribute</span></span><span> </span><span class="annot"><a href="#local-6989586621679157085"><span class="hs-identifier hs-type">a1</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">NodeDef</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Text</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679157085"><span class="hs-identifier hs-type">a1</span></a></span></span><span>
</span><span id="line-997"></span><span id="lookupAttr"><span class="annot"><span class="annottext">lookupAttr :: NodeDef -&gt; Text -&gt; a1
</span><a href="TensorFlow.Gradient.html#lookupAttr"><span class="hs-identifier hs-var hs-var">lookupAttr</span></a></span></span><span> </span><span id="local-6989586621679156410"><span class="annot"><span class="annottext">nodeDef :: NodeDef
</span><a href="#local-6989586621679156410"><span class="hs-identifier hs-var">nodeDef</span></a></span></span><span> </span><span id="local-6989586621679156409"><span class="annot"><span class="annottext">attrName :: Text
</span><a href="#local-6989586621679156409"><span class="hs-identifier hs-var">attrName</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NodeDef
</span><a href="#local-6989586621679156410"><span class="hs-identifier hs-var">nodeDef</span></a></span><span> </span><span class="annot"><span class="annottext">NodeDef -&gt; FoldLike a1 NodeDef NodeDef a1 a1 -&gt; a1
forall s a t b. s -&gt; FoldLike a s t a b -&gt; a
</span><span class="hs-operator hs-var">^.</span></span><span> </span><span class="annot"><span class="annottext">LensLike' (Constant a1) NodeDef (Map Text AttrValue)
forall (f :: * -&gt; *) s a.
(Functor f, HasField s &quot;attr&quot; a) =&gt;
LensLike' f s a
</span><span class="hs-identifier hs-var">attr</span></span><span> </span><span class="annot"><span class="annottext">LensLike' (Constant a1) NodeDef (Map Text AttrValue)
-&gt; ((a1 -&gt; Constant a1 a1)
    -&gt; Map Text AttrValue -&gt; Constant a1 (Map Text AttrValue))
-&gt; FoldLike a1 NodeDef NodeDef a1 a1
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">Text -&gt; Lens' (Map Text AttrValue) (Maybe AttrValue)
forall k v. Ord k =&gt; k -&gt; Lens' (Map k v) (Maybe v)
</span><span class="hs-identifier hs-var">at</span></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679156409"><span class="hs-identifier hs-var">attrName</span></a></span><span> </span><span class="annot"><span class="annottext">LensLike' (Constant a1) (Map Text AttrValue) (Maybe AttrValue)
-&gt; ((a1 -&gt; Constant a1 a1)
    -&gt; Maybe AttrValue -&gt; Constant a1 (Maybe AttrValue))
-&gt; (a1 -&gt; Constant a1 a1)
-&gt; Map Text AttrValue
-&gt; Constant a1 (Map Text AttrValue)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">AttrValue -&gt; Lens' (Maybe AttrValue) AttrValue
forall a. Eq a =&gt; a -&gt; Lens' (Maybe a) a
</span><a href="TensorFlow.Gradient.html#non"><span class="hs-identifier hs-var">non</span></a></span><span> </span><span class="annot"><span class="annottext">AttrValue
forall a. Message a =&gt; a
</span><span class="hs-identifier hs-var">def</span></span><span> </span><span class="annot"><span class="annottext">LensLike' (Constant a1) (Maybe AttrValue) AttrValue
-&gt; ((a1 -&gt; Constant a1 a1) -&gt; AttrValue -&gt; Constant a1 AttrValue)
-&gt; (a1 -&gt; Constant a1 a1)
-&gt; Maybe AttrValue
-&gt; Constant a1 (Maybe AttrValue)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">(a1 -&gt; Constant a1 a1) -&gt; AttrValue -&gt; Constant a1 AttrValue
forall a. Attribute a =&gt; Lens' AttrValue a
</span><span class="hs-identifier hs-var">attrLens</span></span><span>
</span><span id="line-998"></span></pre></body></html>